Documentation ¶
Index ¶
- Constants
- func NewAddressHash(protocol Protocol, value string, nonce uint64) (id.Hash, error)
- func NewAddressHashWithBuffer(protocol Protocol, value string, nonce uint64, data []byte) (id.Hash, error)
- type Address
- func (addr *Address) Equal(other *Address) bool
- func (addr Address) Marshal(buf []byte, rem int) ([]byte, int, error)
- func (addr *Address) Sign(privKey *id.PrivKey) error
- func (addr *Address) SignWithBuffer(privKey *id.PrivKey, buf []byte) error
- func (addr *Address) Signatory() (id.Signatory, error)
- func (addr *Address) SignatoryWithBuffer(buf []byte) (id.Signatory, error)
- func (addr Address) SizeHint() int
- func (addr Address) String() string
- func (addr *Address) Unmarshal(buf []byte, rem int) ([]byte, int, error)
- func (addr *Address) Verify(signatory id.Signatory) error
- func (addr *Address) VerifyWithBuffer(signatory id.Signatory, buf []byte) error
- type Msg
- type Packet
- type Protocol
- type SignatoryAndAddress
Constants ¶
const ( UndefinedProtocol = Protocol(0) TCP = Protocol(1) UDP = Protocol(2) WebSocket = Protocol(3) )
Protocol values for the different network address protocols that are supported.
const ( MsgTypePush = uint16(1) MsgTypePull = uint16(2) MsgTypeSync = uint16(3) MsgTypeSend = uint16(4) MsgTypePing = uint16(5) MsgTypePingAck = uint16(6) )
Enumerate all valid MsgType values.
const (
MsgVersion1 = uint16(1)
)
Enumerate all valid MsgVersion values.
Variables ¶
This section is empty.
Functions ¶
func NewAddressHash ¶
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
DecodeString into a wire-compatible Address.
func NewUnsignedAddress ¶
NewUnsignedAddress returns an Address that has an empty signature. The Sign method should be called before the returned Address is used.
func (*Address) Equal ¶
Equal compares two Addressees. Returns true if they are the same, otherwise returns false.
func (*Address) SignWithBuffer ¶
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 ¶
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 ¶
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 ¶
SizeHint returns the number of bytes needed to represent this Address in binary.
func (Address) String ¶
String returns a human-readable representation of the Address. The string representation is safe for use in URLs and filenames.
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.
type Packet ¶ added in v0.5.3
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 (*Protocol) UnmarshalJSON ¶ added in v0.5.3
type SignatoryAndAddress ¶ added in v0.5.3
func (SignatoryAndAddress) SizeHint ¶ added in v0.5.3
func (sigAndAddr SignatoryAndAddress) SizeHint() int