polity

package module
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Citizen

type Citizen struct {
	Node
	*Oracle
	Peers    PeerSet
	Profiles *ProfileSet
	Log      *log.Logger
}

A Citizen is a Connection with an Oracle.

func NewCitizen

func NewCitizen(randy io.Reader, out io.Writer, node Node) *Citizen

func (*Citizen) Announce

func (c *Citizen) Announce(ctx context.Context, randy io.Reader, letter Letter, recipients []url.URL) error

func (*Citizen) AsPeer

func (c *Citizen) AsPeer() *Peer

func (*Citizen) Compose

func (c *Citizen) Compose(r io.Reader, recipient *url.URL) *Envelope

Compose is a convenience function to create an Envelope intended for a particular recipient

func (*Citizen) ComposePlain

func (c *Citizen) ComposePlain(recipient *url.URL, str string) *Envelope

ComposePlain is an even more convenient convenience function.

func (*Citizen) Establish

func (c *Citizen) Establish(ctx context.Context, kp delphi.KeyPair) error

func (*Citizen) Join

func (c *Citizen) Join(ctx context.Context) (chan Envelope, chan Envelope, chan error, error)

func (*Citizen) Leave

func (c *Citizen) Leave(ctx context.Context, inbox chan Envelope, outbox chan Envelope, errs chan error) error

func (*Citizen) Send

func (c *Citizen) Send(ctx context.Context, randy io.Reader, letter Letter, recipient *url.URL) error

func (*Citizen) Shutdown

func (c *Citizen) Shutdown()

Shutdown sends a signed message to self, telling us to shut down

type Connection

type Connection interface {
	ReadFrom([]byte) (int, net.Addr, error)
	WriteTo([]byte, net.Addr) (int, error)
	LocalAddr() net.Addr
	Close() error
	Node() Node
}

A Connection is a subset of net.PacketConn, with a reference to its parent Node

type Envelope

type Envelope struct {
	Letter    Letter   `json:"letter" msgpack:"letter"`
	Sender    *url.URL `json:"sender,omitempty" msgpack:"sender"`
	Recipient *url.URL `json:"recipient,omitempty" msgpack:"recipient"`
}

An Envelope is a Letter with a recipient and sender

func NewEnvelope

func NewEnvelope(r io.Reader) *Envelope

func (*Envelope) Deserialize

func (e *Envelope) Deserialize(p []byte) error

func (*Envelope) Serialize

func (e *Envelope) Serialize() ([]byte, error)

type Letter

type Letter struct {
	message.Message
	// contains filtered or unexported fields
}

A Letter is a message.Message, but with a subject and headers. Headers are stored in the message's AAD field. Subject is too. It's stored in the "pemType" key. It is an error to have AAD data that cannot be marshaled into a map[string, string].

func NewLetter

func NewLetter(r io.Reader) Letter

func (*Letter) Deserialize

func (letter *Letter) Deserialize(p []byte) error

func (*Letter) Equal

func (letter *Letter) Equal(f Letter) bool

func (*Letter) GetHeader

func (letter *Letter) GetHeader(key string) (string, bool)

func (*Letter) Headers

func (letter *Letter) Headers() (map[string]string, error)

func (*Letter) Serialize

func (letter *Letter) Serialize() []byte

func (*Letter) SetHeader

func (letter *Letter) SetHeader(k, v string) error

func (*Letter) SetHeaders

func (letter *Letter) SetHeaders(m map[string]string) error

func (*Letter) SetSubject

func (letter *Letter) SetSubject(str string) error

func (*Letter) Sign

func (letter *Letter) Sign(r io.Reader, signer crypto.Signer) error

func (*Letter) Subject

func (letter *Letter) Subject() string

func (*Letter) Verify

func (letter *Letter) Verify(v Verifier) error

type Node

type Node interface {
	URL() *url.URL // the address of the Connection, including username
	Connect(ctx context.Context, pair delphi.KeyPair) (Connection, error)
	Disconnect() error
	Connection() Connection
	UrlToAddr(url.URL) (net.Addr, error)
}

A Node is a participant on a network with a unique URL.

type Oracle

type Oracle = oracle.Principal

An Oracle is an oracle.Principal.

type Peer

type Peer struct {
	oracle.Peer
}

A Peer is an oracle.Peer with a convenient way to access its address.

func PeerFromKey

func PeerFromKey(key delphi.PublicKey) *Peer

func PeerFromURL

func PeerFromURL(u *url.URL) *Peer

func (*Peer) Address

func (p *Peer) Address() *url.URL

func (*Peer) Deserialize

func (p *Peer) Deserialize(data []byte) error

func (*Peer) Serialize

func (p *Peer) Serialize() []byte

type PeerSet

type PeerSet struct {
	// contains filtered or unexported fields
}

func NewPeerSet

func NewPeerSet(underlying map[delphi.PublicKey]oracle.Props) PeerSet

func (*PeerSet) Add

func (ps *PeerSet) Add(peer Peer, fn func())

func (*PeerSet) Contains

func (ps *PeerSet) Contains(peer Peer) bool

func (*PeerSet) Get

func (ps *PeerSet) Get(pubKey delphi.PublicKey) *Peer

func (*PeerSet) Len

func (ps *PeerSet) Len() int

func (PeerSet) Minus

func (ps PeerSet) Minus(key delphi.PublicKey) PeerSet

func (*PeerSet) Remove

func (ps *PeerSet) Remove(peer Peer)

func (PeerSet) URLs

func (ps PeerSet) URLs() []url.URL

type PemBag

type PemBag map[string][]pem.Block

func (*PemBag) Add

func (pb *PemBag) Add(key string, block pem.Block)

func (*PemBag) Get

func (pb *PemBag) Get(key string) ([]pem.Block, bool)

func (*PemBag) Size

func (pb *PemBag) Size() int

func (*PemBag) Write

func (pb *PemBag) Write(p []byte) (int, error)

type Profile

type Profile struct {
	PubKey delphi.PublicKey
	Alive  bool
}

A Profile is information about a peer that you don't share with anyone.

type ProfileSet

type ProfileSet map[delphi.PublicKey]Profile

func (*ProfileSet) SetAliveness

func (vs *ProfileSet) SetAliveness(pubKey delphi.PublicKey, alive bool) error

type Verifier

type Verifier interface {
	Verify(pubKey crypto.PublicKey, digest []byte, signature []byte) bool
	Public() crypto.PublicKey
}

Directories

Path Synopsis
cmd
polity command
polityctl command
polityd command
network
lan
mem

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL