...

Package packet

import "vminko.org/dscuss/packet"
Overview
Index

Overview ▾

This file is part of Dscuss. Copyright (C) 2018 Vitaly Minko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This file is part of Dscuss. Copyright (C) 2018 Vitaly Minko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This file is part of Dscuss. Copyright (C) 2018 Vitaly Minko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This file is part of Dscuss. Copyright (C) 2018 Vitaly Minko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This file is part of Dscuss. Copyright (C) 2018 Vitaly Minko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

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