Documentation
¶
Index ¶
- Variables
- type Address
- type AddressConnectMailer
- type AddressConnector
- type Addresser
- type Connector
- type Envelope
- func (e *Envelope[A]) Clone() *Envelope[A]
- func (e *Envelope[A]) Deserialize(data []byte) error
- func (e *Envelope[A]) IsSigned() bool
- func (e *Envelope[A]) Reply() *Envelope[A]
- func (e *Envelope[A]) Serialize() ([]byte, error)
- func (e *Envelope[A]) SetRecipient(p *Peer[A])
- func (e *Envelope[A]) String() string
- func (e *Envelope[A]) Subject(str subj.Subject)
- type Mailer
- type MessageId
- type Peer
- func (p *Peer[A]) Decompose() (delphi.Key, PeerInfo[A])
- func (p *Peer[A]) MarshalBinary() ([]byte, error)
- func (p *Peer[A]) MarshalJSON() ([]byte, error)
- func (p *Peer[A]) MarshalPEM() (*pem.Block, error)
- func (p *Peer[A]) PublicKey() delphi.Key
- func (p *Peer[A]) String() string
- func (p *Peer[A]) UnmarshalBinary(data []byte) error
- func (p *Peer[A]) UnmarshalJSON(data []byte) error
- type PeerInfo
- type PeerMap
- type Principal
- func NewPrincipal[A AddressConnector](rand io.Reader, network A, opts ...PrincipalOption[A]) (*Principal[A], error)
- func PrincipalFromFile[A AddressConnector](s string, network A) (*Principal[A], error)
- func PrincipalFromPEM[A AddressConnector](data []byte, network A) (*Principal[A], error)
- func PrincipalFromPEMBlock[A AddressConnector](block *pem.Block, network A) (*Principal[A], error)
- func (p *Principal[A]) AddPeer(peer *Peer[A]) error
- func (p *Principal[A]) AllPeers() []*Peer[A]
- func (p *Principal[A]) AsPeer() *Peer[A]
- func (p *Principal[A]) Broadcast(e *Envelope[A])
- func (p *Principal[A]) BroadcastParallel(e *Envelope[A])
- func (p *Principal[A]) Compose(body []byte, recipient *Peer[A], thread *MessageId) *Envelope[A]
- func (p *Principal[A]) Connect() error
- func (p *Principal[A]) Disconnect() error
- func (p *Principal[A]) EachPeer() iter.Seq[*Peer[A]]
- func (p *Principal[A]) Inbox() chan Envelope[A]
- func (p *Principal[A]) MarshalPEM() (*pem.Block, error)
- func (p *Principal[A]) Send(e *Envelope[A]) (int, error)
- func (p *Principal[A]) SetPeerAliveness(peer *Peer[A], val bool) error
- func (p *Principal[A]) Shutdown()
- func (p *Principal[A]) UnmarshalPEM(data []byte, network A) error
- func (p *Principal[A]) UnmarshalPEMBlock(block *pem.Block, network A) error
- func (p *Principal[AddressConnector]) With(fn PrincipalOption[AddressConnector])
- type PrincipalOption
- type UDPAddr
Constants ¶
This section is empty.
Variables ¶
var ErrPeerExists = errors.New("peer exists")
Functions ¶
This section is empty.
Types ¶
type AddressConnectMailer ¶
type AddressConnectMailer interface {
AddressConnector
Mailer
}
type AddressConnector ¶
type AddressConnector interface {
Addresser
Connector
New() AddressConnector
}
An AddressConnector is an Addresser and Connector. It allows a node to accept and issue requests over the network.
type Addresser ¶
type Addresser interface {
net.Addr
encoding.TextMarshaler
encoding.TextUnmarshaler
Addr() net.Addr
}
An Addresser provides a network address and a way to serialize/deserialize it
type Connector ¶
type Connector interface {
Initialize()
Connection() (net.PacketConn, error) // persistent connection
NewConnection() (net.PacketConn, error) // for ephemeral one-off connections
Close() error
}
A Connector provides one persistent and one ad hoc packet connection. The ephemeral connection should be closed after each use. The persistent connection should be closed at shutdown
type Envelope ¶
type Envelope[A Addresser] struct { ID *MessageId `json:"id" msgpack:"id"` Thread *MessageId `json:"thread" msgpack:"thread"` Sender *Peer[A] `json:"sender" msgpack:"sender"` Recipient *Peer[A] `json:"recipient" msgpack:"recipient"` Message *delphi.Message `json:"msg" msgpack:"msg"` }
An Envelope wraps a delphi.Message with information essential for addressing and organizing.
func NewEnvelope ¶
NewEnvelope creates a new Envelope, ensuring there are no nil pointers
func (*Envelope[A]) Deserialize ¶
func (*Envelope[A]) Reply ¶
Reply crafts an Envelope whose recipient is the sender, and whose threadId points back to the original
func (*Envelope[A]) SetRecipient ¶
type Mailer ¶
type Mailer interface {
Send(envelope Envelope[Addresser]) error
SendEphemeral(envelope Envelope[Addresser]) error
Receive() chan Envelope[Addresser]
}
A Mailer can route [Envelope]s to a destination and receive them too.
type MessageId ¶
func NewMessageId ¶
func NewMessageId() *MessageId
type Peer ¶
A Peer is a public key, some arbitrary key-value pairs, and an address on network N
func (*Peer[A]) MarshalBinary ¶
func (*Peer[A]) MarshalJSON ¶
func (*Peer[A]) UnmarshalBinary ¶
func (*Peer[A]) UnmarshalJSON ¶
type PeerInfo ¶
type PeerInfo[A Addresser] struct { IsAlive bool Closeness int Trust int Addr A Props *stablemap.StableMap[string, string] }
PeerInfo contains everything that can be known about a Peer except for its pubKey, which is kept elsewhere.
func NewPeerInfo ¶
type Principal ¶
type Principal[A AddressConnector] struct { *goracle.Principal Net A Peers *stablemap.ActiveMap[delphi.Key, PeerInfo[A]] Slogger *slog.Logger Logger *log.Logger // contains filtered or unexported fields }
A Principal is an entity (node) in the graph (cluster) that can: - send messages - listen for messages - encrypt, decrypt, sign, and verify signatures - keep track of [Peer]s, which represent "friends" - read and write to a [KnowledgeBase] containing knowledge of the graph
func NewPrincipal ¶
func NewPrincipal[A AddressConnector](rand io.Reader, network A, opts ...PrincipalOption[A]) (*Principal[A], error)
func PrincipalFromFile ¶
func PrincipalFromFile[A AddressConnector](s string, network A) (*Principal[A], error)
func PrincipalFromPEM ¶
func PrincipalFromPEM[A AddressConnector](data []byte, network A) (*Principal[A], error)
func PrincipalFromPEMBlock ¶
func PrincipalFromPEMBlock[A AddressConnector](block *pem.Block, network A) (*Principal[A], error)
func (*Principal[A]) BroadcastParallel ¶
func (*Principal[A]) Compose ¶
Compose a delphi.Message, wrapped in an Envelope, addressed to a particular Peer.
func (*Principal[A]) Connect ¶
Connect acquires an address and starts listening on it. After doing so, a node will probably want to advertise itself. It will probably also want to process incoming data using [Inbox].
func (*Principal[A]) Disconnect ¶
func (*Principal[A]) SetPeerAliveness ¶
func (*Principal[A]) UnmarshalPEM ¶
func (*Principal[A]) UnmarshalPEMBlock ¶
func (*Principal[AddressConnector]) With ¶
func (p *Principal[AddressConnector]) With(fn PrincipalOption[AddressConnector])
type PrincipalOption ¶
type PrincipalOption[A AddressConnector] func(principal *Principal[A])
func WithLogger ¶
func WithLogger[A AddressConnector](log *log.Logger) PrincipalOption[A]
func WithSlogger ¶
func WithSlogger[A AddressConnector](slog *slog.Logger) PrincipalOption[A]