Package packet

import "vminko.org/dscuss/packet"

Overview ▾

type Body

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"`

type Packet

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

func New(t Type, rcv *entity.ID, pld interface{}, s *crypto.Signer) *Packet

func (*Packet) DecodePayload

func (p *Packet) DecodePayload() (interface{}, error)

func (*Packet) Dump

func (p *Packet) Dump() string

func (*Packet) String

func (p *Packet) String() string

func (*Packet) VerifyHeader

func (p *Packet) VerifyHeader(t Type, rcv *entity.ID) error

func (*Packet) VerifyHeaderFull

func (p *Packet) VerifyHeaderFull(f func(Type) bool, rcv *entity.ID) error

func (*Packet) VerifySig

func (p *Packet) VerifySig(pubKey *crypto.PublicKey) bool

type PayloadAck

PayloadAck is used as an acknowledgment for an announcement.

type PayloadAck struct {

func NewPayloadAck

func NewPayloadAck() *PayloadAck

type PayloadAnnounce

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

func NewPayloadAnnounce(id *entity.ID) *PayloadAnnounce

type PayloadDone

PayloadDone indicates the end of active synchronization process.

type PayloadDone struct {

func NewPayloadDone

func NewPayloadDone() *PayloadDone

type PayloadHello

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

func NewPayloadHello(p int, s subs.Subscriptions) *PayloadHello

func (*PayloadHello) IsValid

func (p *PayloadHello) IsValid() bool

type PayloadReq

PayloadReq is used for requesting advertised entities.

type PayloadReq struct {
    ID entity.ID `json:"new_id"` // Id of the entity being requested

func NewPayloadReq

func NewPayloadReq(id *entity.ID) *PayloadReq

type Type

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"
    // Done indicated that a complex process (like syncing) is over.
    TypeDone Type = "done"