wire

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 11 Imported by: 10

Documentation

Index

Constants

View Source
const (
	UndefinedProtocol = Protocol(0)
	TCP               = Protocol(1)
	UDP               = Protocol(2)
	WebSocket         = Protocol(3)
)

Protocol values for the different network address protocols that are supported.

View Source
const (
	MsgTypePush    = uint16(1)
	MsgTypePull    = uint16(2)
	MsgTypeSync    = uint16(3)
	MsgTypeSend    = uint16(4)
	MsgTypePing    = uint16(5)
	MsgTypePingAck = uint16(6)
)

Enumerate all valid MsgType values.

View Source
const (
	MsgVersion1 = uint16(1)
)

Enumerate all valid MsgVersion values.

Variables

This section is empty.

Functions

func NewAddressHash

func NewAddressHash(protocol Protocol, value string, nonce uint64) (id.Hash, error)

NewAddressHash returns the Hash of an Address for signing by the peer. An error is returned when the arguments too large and cannot be marshaled into bytes without exceeding memory allocation restrictions.

func NewAddressHashWithBuffer

func NewAddressHashWithBuffer(protocol Protocol, value string, nonce uint64, data []byte) (id.Hash, error)

NewAddressHashWithBuffer writes the Hash of an Address into a bytes buffer for signing by the peer. An error is returned when the arguments are too large and cannot be marshaled into bytes without exceeding memory allocation restrictions. This function is useful when doing a lot of hashing, because it allows for buffer re-use.

Types

type Address

type Address struct {
	Protocol  Protocol     `json:"protocol"`
	Value     string       `json:"value"`
	Nonce     uint64       `json:"nonce"`
	Signature id.Signature `json:"signature"`
}

An Address is a verifiable and expirable network address associated with a specific peer. The peer can be verified by checking the Signatory of the peer against the Signature in the Address. The Address can be expired by issuing a new Address for the same peer, using a later nonce. By convention, nonces are interpreted as seconds since UNIX epoch.

func DecodeString added in v0.5.3

func DecodeString(addr string) (Address, error)

DecodeString into a wire-compatible Address.

func NewUnsignedAddress

func NewUnsignedAddress(protocol Protocol, value string, nonce uint64) Address

NewUnsignedAddress returns an Address that has an empty signature. The Sign method should be called before the returned Address is used.

func (*Address) Equal

func (addr *Address) Equal(other *Address) bool

Equal compares two Addressees. Returns true if they are the same, otherwise returns false.

func (Address) Marshal

func (addr Address) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal this Address into binary.

func (*Address) Sign

func (addr *Address) Sign(privKey *id.PrivKey) error

Sign this Address and set its Signature.

func (*Address) SignWithBuffer

func (addr *Address) SignWithBuffer(privKey *id.PrivKey, buf []byte) error

SignWithBuffer will Sign the Address and set its Signature. It uses a Buffer for all marshaling to allow for buffer re-use.

func (*Address) Signatory

func (addr *Address) Signatory() (id.Signatory, error)

Signatory returns the Signatory from the Address, based on the Signature. If the Address is unsigned, then the empty Signatory is returned.

func (*Address) SignatoryWithBuffer

func (addr *Address) SignatoryWithBuffer(buf []byte) (id.Signatory, error)

SignatoryWithBuffer returns the Signatory from the Address, based on the Signature. If the Address is unsigned, then the empty Signatory is returned. It uses a Buffer for all marshaling to allow for buffer re-use.

func (Address) SizeHint

func (addr Address) SizeHint() int

SizeHint returns the number of bytes needed to represent this Address in binary.

func (Address) String

func (addr Address) String() string

String returns a human-readable representation of the Address. The string representation is safe for use in URLs and filenames.

func (*Address) Unmarshal

func (addr *Address) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary into this Address.

func (*Address) Verify

func (addr *Address) Verify(signatory id.Signatory) error

Verify that the Address was signed by a specific Signatory.

func (*Address) VerifyWithBuffer

func (addr *Address) VerifyWithBuffer(signatory id.Signatory, buf []byte) error

VerifyWithBuffer will verify that the Address was signed by a specific Signatory. It uses a Buffer for all marshaling to allow for buffer re-use.

type Msg added in v0.5.3

type Msg struct {
	Version  uint16  `json:"version"`
	Type     uint16  `json:"type"`
	To       id.Hash `json:"to"`
	Data     []byte  `json:"data"`
	SyncData []byte  `json:"syncData"`
}

Msg defines the low-level message structure that is sent on-the-wire between peers.

func (Msg) Marshal added in v0.5.3

func (msg Msg) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal a Msg to binary.

func (Msg) SizeHint added in v0.5.3

func (msg Msg) SizeHint() int

SizeHint returns the number of bytes required to represent a Msg in binary.

func (*Msg) Unmarshal added in v0.5.3

func (msg *Msg) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal a Msg from binary.

type Packet added in v0.5.3

type Packet struct {
	Msg    Msg
	IPAddr net.Addr
}

Packet defines a struct that captures the incoming message and the corresponding IP address

type Protocol added in v0.5.3

type Protocol uint8

Protocol defines the network protocol used by an address for sending/receiving data over-the-wire.

func (Protocol) MarshalJSON added in v0.5.3

func (p Protocol) MarshalJSON() ([]byte, error)

func (Protocol) String added in v0.5.3

func (p Protocol) String() string

func (*Protocol) UnmarshalJSON added in v0.5.3

func (p *Protocol) UnmarshalJSON(data []byte) error

type SignatoryAndAddress added in v0.5.3

type SignatoryAndAddress struct {
	Signatory id.Signatory
	Address   Address
}

func (SignatoryAndAddress) Marshal added in v0.5.3

func (sigAndAddr SignatoryAndAddress) Marshal(buf []byte, rem int) ([]byte, int, error)

func (SignatoryAndAddress) SizeHint added in v0.5.3

func (sigAndAddr SignatoryAndAddress) SizeHint() int

func (*SignatoryAndAddress) Unmarshal added in v0.5.3

func (sigAndAddr *SignatoryAndAddress) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Jump to

Keyboard shortcuts

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