Documentation ¶
Index ¶
- Constants
- type EncryptedPacket
- type GetNodesPacket
- type Identity
- func (i *Identity) DecryptBlob(data []byte, publicKey *PublicKey, nonce *[crypto.NonceSize]byte) ([]byte, error)
- func (i *Identity) DecryptPacket(p *EncryptedPacket) (Packet, error)
- func (i *Identity) EncryptBlob(data []byte, publicKey *PublicKey) ([]byte, *[crypto.NonceSize]byte, error)
- func (i *Identity) EncryptPacket(packet Packet, publicKey *PublicKey) (*EncryptedPacket, error)
- type IdentityOptions
- type Node
- type NodeType
- type Packet
- type PacketType
- type PingRequestPacket
- type PingResponsePacket
- type PublicKey
- type SendNodesPacket
Constants ¶
const PublicKeySize = crypto.PublicKeySize
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncryptedPacket ¶
type EncryptedPacket struct { Type PacketType SenderPublicKey *PublicKey Nonce *[crypto.NonceSize]byte Payload []byte /* encrypted */ }
EncryptedPacket represents an encrypted DHT packet.
func (*EncryptedPacket) MarshalBinary ¶
func (p *EncryptedPacket) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*EncryptedPacket) UnmarshalBinary ¶
func (p *EncryptedPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryMarshaler interface.
type GetNodesPacket ¶
GetNodesPacket represents the encrypted portion of the GetNodes request.
func (GetNodesPacket) ID ¶
func (p GetNodesPacket) ID() PacketType
ID returns the packet ID of this packet.
func (*GetNodesPacket) MarshalBinary ¶
func (p *GetNodesPacket) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*GetNodesPacket) UnmarshalBinary ¶
func (p *GetNodesPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryMarshaler interface.
type Identity ¶
type Identity struct { PublicKey *PublicKey SecretKey *[crypto.SecretKeySize]byte // contains filtered or unexported fields }
Identity represents a DHT identity.
func NewIdentity ¶
func NewIdentity(opts IdentityOptions) (*Identity, error)
NewIdentity creates a new DHT identity and generates a new keypair for it.
func (*Identity) DecryptBlob ¶
func (i *Identity) DecryptBlob(data []byte, publicKey *PublicKey, nonce *[crypto.NonceSize]byte) ([]byte, error)
DecryptBlob decrypts the given slice of data.
func (*Identity) DecryptPacket ¶
func (i *Identity) DecryptPacket(p *EncryptedPacket) (Packet, error)
DecryptPacket decrypts the given packet.
func (*Identity) EncryptBlob ¶
func (i *Identity) EncryptBlob(data []byte, publicKey *PublicKey) ([]byte, *[crypto.NonceSize]byte, error)
EncryptBlob encrypts the given slice of data.
func (*Identity) EncryptPacket ¶
func (i *Identity) EncryptPacket(packet Packet, publicKey *PublicKey) (*EncryptedPacket, error)
EncryptPacket encrypts the given packet.
type IdentityOptions ¶
type IdentityOptions struct { int }SharedKeyCacheSize
type Node ¶
Node represents a node in the DHT.
func (*Node) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Node) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type NodeType ¶
type NodeType byte
func (*NodeType) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Packet ¶
type Packet interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler ID() PacketType }
type PacketType ¶
type PacketType byte
const ( PacketTypePingRequest PacketType = 0x00 PacketTypePingResponse PacketType = 0x01 PacketTypeGetNodes PacketType = 0x02 PacketTypeSendNodes PacketType = 0x04 )
func (PacketType) String ¶
func (t PacketType) String() string
type PingRequestPacket ¶
type PingRequestPacket struct { //ping type: 0x00 PingID uint64 }
PingRequestPacket represents the encrypted portion of the PingRequest packet.
func (PingRequestPacket) ID ¶
func (p PingRequestPacket) ID() PacketType
ID returns the packet ID of this packet.
func (*PingRequestPacket) MarshalBinary ¶
func (p *PingRequestPacket) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*PingRequestPacket) UnmarshalBinary ¶
func (p *PingRequestPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type PingResponsePacket ¶
type PingResponsePacket struct { //ping type: 0x01 PingID uint64 }
PingResponsePacket represents the encrypted portion of the PingResponse packet.
func (PingResponsePacket) ID ¶
func (p PingResponsePacket) ID() PacketType
ID returns the packet ID of this packet.
func (*PingResponsePacket) MarshalBinary ¶
func (p *PingResponsePacket) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*PingResponsePacket) UnmarshalBinary ¶
func (p *PingResponsePacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type PublicKey ¶
type PublicKey [PublicKeySize]byte
func (*PublicKey) DistanceTo ¶
func (pk1 *PublicKey) DistanceTo(pk2 *PublicKey) *[PublicKeySize]byte
type SendNodesPacket ¶
SendNodesPacket represents the encrypted portion of the SendNodes packet.
func (SendNodesPacket) ID ¶
func (p SendNodesPacket) ID() PacketType
ID returns the packet ID of this packet.
func (*SendNodesPacket) MarshalBinary ¶
func (p *SendNodesPacket) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*SendNodesPacket) UnmarshalBinary ¶
func (p *SendNodesPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.