dht

package
v0.0.0-...-f2fe5c7 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PacketIDPingRequest  byte = 0
	PacketIDPingResponse byte = 1
	PacketIDGetNodes     byte = 2
	PacketIDSendNodes    byte = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetNodesPacket

type GetNodesPacket struct {
	PublicKey *[crypto.PublicKeySize]byte
	PingID    uint64
}

GetNodesPacket represents the encrypted portion of the GetNodes request.

func (GetNodesPacket) ID

func (p GetNodesPacket) ID() byte

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 Ident

type Ident struct {
	PublicKey *[crypto.PublicKeySize]byte
	SecretKey *[crypto.SecretKeySize]byte
}

Ident represents a DHT identity.

func NewIdent

func NewIdent() (*Ident, error)

NewIdent creates a new DHT identity and generates a new keypair for it.

func (*Ident) DecryptBlob

func (i *Ident) DecryptBlob(data []byte, publicKey *[crypto.PublicKeySize]byte, nonce *[crypto.NonceSize]byte) ([]byte, error)

DecryptBlob decrypts the given slice of data.

func (*Ident) DecryptPacket

func (i *Ident) DecryptPacket(p *Packet) (transport.Packet, error)

DecryptPacket decrypts the given packet.

func (*Ident) EncryptBlob

func (i *Ident) EncryptBlob(data []byte, publicKey *[crypto.PublicKeySize]byte) ([]byte, *[crypto.NonceSize]byte, error)

EncryptBlob encrypts the given slice of data.

func (*Ident) EncryptPacket

func (i *Ident) EncryptPacket(packet transport.Packet, publicKey *[crypto.PublicKeySize]byte) (*Packet, error)

EncryptPacket encrypts the given packet.

type Node

type Node struct {
	Type      NodeType
	PublicKey *[crypto.PublicKeySize]byte
	IP        net.IP
	Port      int
}

Node represents a node in the DHT.

func (*Node) MarshalBinary

func (n *Node) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Node) UnmarshalBinary

func (n *Node) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type NodeType

type NodeType byte

NodeType represents the type of Node. This can be a regular node (UDP) or a TCP relay.

const (
	// NodeTypeUDP represents the UDP node type.
	NodeTypeUDP NodeType = iota
	// NodeTypeTCP represents the TCP node type.
	NodeTypeTCP
)

type Packet

type Packet struct {
	Type            byte
	SenderPublicKey *[crypto.PublicKeySize]byte
	Nonce           *[crypto.NonceSize]byte
	Payload         []byte /* encrypted */
}

Packet represents the base of all DHT packets.

func (*Packet) MarshalBinary

func (p *Packet) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryMarshaler interface.

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() byte

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() byte

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 SendNodesPacket

type SendNodesPacket struct {
	Nodes  []*Node
	PingID uint64
}

SendNodesPacket represents the encrypted portion of the SendNodes packet.

func (SendNodesPacket) ID

func (p SendNodesPacket) ID() byte

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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