Time and ReceiverID protect from replay attack.
type Body struct { Type Type `json:"type"` ReceiverID entity.ID `json:"receiver_id"` // Id of the user this packet is designated for. DateComposed time.Time `json:"date_composed"` // Date and time when the payload was composed. Payload json.RawMessage `json:"payload"` }
Packet is a unit of raw data for communication between peers.
type Packet struct { Body Body `json:"body"` Sig crypto.Signature `json:"sig"` }
func New(t Type, rcv *entity.ID, pld interface{}, s *crypto.Signer) *Packet
func (p *Packet) DecodePayload() (interface{}, error)
func (p *Packet) Dump() string
func (p *Packet) String() string
func (p *Packet) VerifyHeader(t Type, rcv *entity.ID) error
func (p *Packet) VerifyHeaderFull(f func(Type) bool, rcv *entity.ID) error
func (p *Packet) VerifySig(pubKey *crypto.PublicKey) bool
PayloadAck is used as an acknowledgment for an announcement.
type PayloadAck struct { }
func NewPayloadAck() *PayloadAck
PayloadAnnounce is used for advertising new entities. When user A sends this packet to user B, he/she notifies user B about new entity that should be interesting for B.
type PayloadAnnounce struct { ID entity.ID `json:"id"` // Id of the entity being advertised. }
func NewPayloadAnnounce(id *entity.ID) *PayloadAnnounce
PayloadHello is used for introducing peers during handshake. When user A sends this packet to user B, he/she notifies user B about topics of A's interests/
type PayloadHello struct { Proto int `json:"proto"` // The version of the protocol this peer supports. Subs subs.Subscriptions `json:"subs"` // Subscriptions of the author of the payload. }
func NewPayloadHello(p int, s subs.Subscriptions) *PayloadHello
func (p *PayloadHello) IsValid() bool
PayloadReq is used for requesting advertised entities.
type PayloadReq struct { ID entity.ID `json:"new_id"` // Id of the entity being requested }
func NewPayloadReq(id *entity.ID) *PayloadReq
type Type string
const ( // Encapsulates a user entity. TypeUser Type = "user" // Encapsulates a message entity. TypeMessage Type = "msg" // Encapsulates an operation entity. TypeOperation Type = "oper" // Used for introducing users during handshake. TypeHello Type = "hello" // Used for advertising new entities. TypeAnnounce Type = "ann" // Acknowledgment for an announcement. TypeAck Type = "ack" // Request for an entity. TypeReq Type = "req" )