Documentation
¶
Overview ¶
Package gossip provides Rust-compatible iroh-gossip transport helpers.
The package implements the unidirectional stream framing used by iroh-gossip. Higher-level topic orchestration and discovery live in later layers.
The Go API is not stable before v1 and may change in any v0 release.
Index ¶
- Constants
- Variables
- type DeliveryScope
- type Discovery
- type Event
- type EventKind
- type Gossip
- func (g *Gossip) Accept(ctx context.Context, conn *iroh.Conn) error
- func (g *Gossip) Handler() iroh.ProtocolHandler
- func (g *Gossip) MaxMessageSize() int
- func (g *Gossip) Metrics() Metrics
- func (g *Gossip) Shutdown(ctx context.Context)
- func (g *Gossip) Subscribe(ctx context.Context, topic TopicID, bootstrap []netaddr.EndpointAddr) (*Topic, error)
- func (g *Gossip) SubscribeAndJoin(ctx context.Context, topic TopicID, bootstrap []netaddr.EndpointAddr) (*Topic, error)
- func (g *Gossip) SubscribeWithOpts(ctx context.Context, topic TopicID, opts JoinOptions) (*Topic, error)
- type GossipOption
- type Handler
- type JoinOptions
- type Message
- type Metrics
- type Option
- type PeerID
- type Receiver
- type Sender
- func (s *Sender) Broadcast(ctx context.Context, content []byte) error
- func (s *Sender) BroadcastNeighbors(ctx context.Context, content []byte) error
- func (s *Sender) Close() error
- func (s *Sender) JoinPeers(ctx context.Context, peers []netaddr.EndpointAddr) error
- func (s *Sender) Send(ctx context.Context, msg Message) error
- type Topic
- func (t *Topic) Broadcast(ctx context.Context, content []byte) error
- func (t *Topic) BroadcastNeighbors(ctx context.Context, content []byte) error
- func (t *Topic) Close() error
- func (t *Topic) Events() iter.Seq2[Event, error]
- func (t *Topic) ID() TopicID
- func (t *Topic) IsJoined() bool
- func (t *Topic) JoinPeers(ctx context.Context, peers []netaddr.EndpointAddr) error
- func (t *Topic) Joined(ctx context.Context) error
- func (t *Topic) Neighbors() []key.EndpointID
- func (t *Topic) Split() (*Sender, *Receiver)
- type TopicID
- type TopicMessage
Examples ¶
Constants ¶
const ALPN = gossipproto.ALPN
ALPN is the Rust iroh-gossip application protocol name.
const (
// Provenance is the provenance reported on resolved gossip discovery items.
Provenance = "gossip"
)
Variables ¶
var DefaultDiscoveryTopic = TopicID(blake3.Sum256([]byte("iroh-gossip-discovery-v1")))
DefaultDiscoveryTopic is the default topic used by Discovery.
Functions ¶
This section is empty.
Types ¶
type DeliveryScope ¶
type DeliveryScope uint8
DeliveryScope identifies how a received message was delivered.
const ( // DeliverySwarm reports an epidemic overlay delivery. DeliverySwarm DeliveryScope = iota // DeliveryNeighbors reports a direct-neighbor delivery. DeliveryNeighbors )
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery publishes and resolves endpoint addressing information over a gossip topic. The zero value is not usable; create one with New.
Example ¶
package main
import (
"fmt"
"github.com/tmc/go-iroh/gossip"
"github.com/tmc/go-iroh/iroh"
"github.com/tmc/go-iroh/key"
)
func main() {
sk, _ := key.GenerateSecretKey()
discovery := gossip.New(sk.Public().EndpointID())
var services iroh.AddressLookupServices
services.AddPublisher(discovery)
services.AddResolver(discovery)
fmt.Println(discovery != nil)
}
Output: true
func (*Discovery) Publish ¶
func (d *Discovery) Publish(data dns.EndpointData)
Publish advertises data on the gossip topic. It is fire-and-forget and returns immediately, matching iroh.AddressPublisher.
type Event ¶
type Event struct {
Kind EventKind
Peer key.EndpointID
Data []byte
Content []byte
DeliveredFrom key.EndpointID
Scope DeliveryScope
// Round is the PlumTree delivery round for DeliverySwarm messages.
// It is zero for direct-neighbor delivery.
Round uint16
}
Event is emitted by a subscribed gossip topic.
type EventKind ¶
type EventKind uint8
EventKind identifies a topic event.
const ( // NeighborUp reports a new direct neighbor for the topic. NeighborUp EventKind = iota // NeighborDown reports a dropped direct neighbor for the topic. NeighborDown // Received reports an application gossip message. Received // PeerData reports metadata propagated by the topic membership overlay. PeerData // Lagged reports that a slow receiver missed one or more events. Lagged )
type Gossip ¶
type Gossip struct {
// contains filtered or unexported fields
}
Gossip publishes and subscribes to iroh-gossip topics.
Register Gossip.Handler with an iroh Router under ALPN.
func NewGossip ¶
func NewGossip(ep *iroh.Endpoint, opts ...GossipOption) *Gossip
NewGossip returns a Gossip instance for ep.
func (*Gossip) Handler ¶
func (g *Gossip) Handler() iroh.ProtocolHandler
Handler returns the protocol handler for registering this Gossip with an iroh Router.
func (*Gossip) MaxMessageSize ¶
MaxMessageSize returns the normalized gossip frame body size.
func (*Gossip) Subscribe ¶
func (g *Gossip) Subscribe(ctx context.Context, topic TopicID, bootstrap []netaddr.EndpointAddr) (*Topic, error)
Subscribe joins topic and returns a local handle for publishing and receiving events. Bootstrap peers are dialed as needed.
func (*Gossip) SubscribeAndJoin ¶
func (g *Gossip) SubscribeAndJoin(ctx context.Context, topic TopicID, bootstrap []netaddr.EndpointAddr) (*Topic, error)
SubscribeAndJoin subscribes to topic and waits until it has a direct neighbor.
func (*Gossip) SubscribeWithOpts ¶
func (g *Gossip) SubscribeWithOpts(ctx context.Context, topic TopicID, opts JoinOptions) (*Topic, error)
SubscribeWithOpts joins topic with opts and returns a local handle for publishing and receiving events.
type GossipOption ¶
type GossipOption func(*Gossip)
GossipOption configures a Gossip instance.
func WithMaxMessageSize ¶
func WithMaxMessageSize(n int) GossipOption
WithMaxMessageSize sets the maximum postcard frame body size. Non-positive values use the Rust default.
type Handler ¶
type Handler struct {
// MaxMessageSize limits postcard frame bodies. The zero value uses the Rust
// default.
MaxMessageSize int
// Handle is called for each received message. A nil Handle discards
// messages after validating their frames.
Handle func(context.Context, key.EndpointID, Message) error
}
Handler receives gossip messages from accepted iroh connections.
type JoinOptions ¶
type JoinOptions struct {
Bootstrap []netaddr.EndpointAddr
SubscriptionCapacity int
}
JoinOptions configures a topic subscription.
type Message ¶
type Message = gossipproto.Message
Message is one topic-scoped gossip protocol message.
type Metrics ¶
type Metrics struct {
MsgsCtrlSent uint64
MsgsCtrlRecv uint64
MsgsDataSent uint64
MsgsDataRecv uint64
MsgsDataSentSize uint64
MsgsDataRecvSize uint64
MsgsCtrlSentSize uint64
MsgsCtrlRecvSize uint64
NeighborUp uint64
NeighborDown uint64
ActorTickMain uint64
ActorTickRx uint64
ActorTickEndpoint uint64
ActorTickDialer uint64
ActorTickDialerSuccess uint64
ActorTickDialerFailure uint64
ActorTickInEventRx uint64
ActorTickTimers uint64
}
Metrics is a snapshot of gossip counters.
func (Metrics) Snapshot ¶
Snapshot returns m as named counter values for metrics.Registry.
type Option ¶
type Option func(*Discovery)
Option configures a Discovery.
func WithGossip ¶
func WithGossip(g *Gossip, topic TopicID, bootstrap []netaddr.EndpointAddr) Option
WithGossip configures the gossip overlay used by a Discovery.
func WithLookupTimeout ¶
WithLookupTimeout sets how long Resolve waits after a cache miss.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver receives events for a gossip topic.
func (*Receiver) IsJoined ¶
IsJoined reports whether the receiver's topic has at least one direct neighbor.
func (*Receiver) Neighbors ¶
func (r *Receiver) Neighbors() []key.EndpointID
Neighbors returns the receiver's current direct neighbors.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender writes gossip messages to an iroh connection.
func (*Sender) BroadcastNeighbors ¶
BroadcastNeighbors sends content to the sender's direct topic neighbors.
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic is a local subscription to one gossip topic.
func (*Topic) BroadcastNeighbors ¶
BroadcastNeighbors sends content to the topic's direct neighbors.
func (*Topic) Neighbors ¶
func (t *Topic) Neighbors() []key.EndpointID
Neighbors returns the topic's current direct neighbors.
type TopicMessage ¶
type TopicMessage = gossipproto.TopicMessage
TopicMessage is either a membership or broadcast message.