Documentation ¶
Index ¶
- Constants
- func NodeFinderUseLogger(l *logrus.Logger)
- func RoutingTableRefresh(n *Node, refreshInterval time.Duration, parentGrp *stop.Group)
- func TestingCreateNetwork(t *testing.T, numNodes int, bootstrap, concurrent bool) (*BootstrapNode, []*DHT)
- func UseLogger(l *logrus.Logger)
- type BootstrapNode
- type Config
- type Contact
- func (c Contact) Addr() *net.UDPAddr
- func (c Contact) Equals(other Contact, checkID bool) bool
- func (c Contact) MarshalBencode() ([]byte, error)
- func (c Contact) MarshalCompact() ([]byte, error)
- func (c Contact) MarshalJSON() ([]byte, error)
- func (c Contact) String() string
- func (c *Contact) UnmarshalBencode(b []byte) error
- func (c *Contact) UnmarshalCompact(b []byte) error
- type DHT
- func (dht *DHT) Add(hash bits.Bitmap)
- func (dht *DHT) Get(hash bits.Bitmap) ([]Contact, error)
- func (dht DHT) ID() bits.Bitmap
- func (dht *DHT) Ping(addr string) error
- func (dht *DHT) PrintState()
- func (dht *DHT) Remove(hash bits.Bitmap)
- func (dht *DHT) Shutdown()
- func (dht *DHT) Start() error
- func (dht *DHT) WaitUntilJoined()
- type Error
- type Message
- type Node
- func (n *Node) AddKnownNode(c Contact)
- func (n *Node) Connect(conn UDPConn) error
- func (n *Node) CountActiveTransactions() int
- func (n *Node) Send(contact Contact, req Request, options ...SendOptions) *Response
- func (n *Node) SendAsync(contact Contact, req Request, options ...SendOptions) <-chan *Response
- func (n *Node) Shutdown()
- func (n *Node) Store(hash bits.Bitmap, c Contact)
- type Request
- type RequestHandlerFunc
- type Response
- type RpcBucketResponse
- type RpcFindArgs
- type RpcFindValueResult
- type RpcIterativeFindValueArgs
- type RpcIterativeFindValueResult
- type RpcPingArgs
- type RpcRoutingTableResponse
- type SendOptions
- type UDPConn
Constants ¶
const ( Network = "udp4" DefaultPort = 4444 DefaultPeerPort = 3333 DefaultAnnounceRate = 10 // send at most this many announces per second DefaultReannounceTime = 50 * time.Minute // should be a bit less than hash expiration time )
Variables ¶
This section is empty.
Functions ¶
func NodeFinderUseLogger ¶
func RoutingTableRefresh ¶
RoutingTableRefresh refreshes any buckets that need to be refreshed
func TestingCreateNetwork ¶
func TestingCreateNetwork(t *testing.T, numNodes int, bootstrap, concurrent bool) (*BootstrapNode, []*DHT)
TestingCreateNetwork initializes a testable DHT network with a specific number of nodes, with bootstrap and concurrent options.
Types ¶
type BootstrapNode ¶
type BootstrapNode struct { Node // contains filtered or unexported fields }
BootstrapNode is a configured node setup for testing.
func NewBootstrapNode ¶
func NewBootstrapNode(id bits.Bitmap, initialPingInterval, rePingInterval time.Duration) *BootstrapNode
NewBootstrapNode returns a BootstrapNode pointer.
func (*BootstrapNode) Connect ¶
func (b *BootstrapNode) Connect(conn UDPConn) error
Connect connects to the given connection and starts any background threads necessary
type Config ¶
type Config struct { // this node's address. format is `ip:port` Address string // the seed nodes through which we can join in dht network SeedNodes []string // the hex-encoded node id for this node. if string is empty, a random id will be generated NodeID string // print the state of the dht every X time PrintState time.Duration // the port that clients can use to download blobs using the LBRY peer protocol PeerProtocolPort int // if nonzero, an RPC server will listen to requests on this port and respond to them RPCPort int // the time after which the original publisher must reannounce a key/value pair ReannounceTime time.Duration // send at most this many announces per second AnnounceRate int // channel that will receive notifications about announcements AnnounceNotificationCh chan announceNotification }
Config represents the configure of dht.
func NewStandardConfig ¶
func NewStandardConfig() *Config
NewStandardConfig returns a Config pointer with default values.
type Contact ¶
type Contact struct { ID bits.Bitmap IP net.IP Port int // the udp port used for the dht PeerPort int // the tcp port a peer can be contacted on for blob requests }
Contact contains information for contacting another node on the network
func FindContacts ¶
func (Contact) MarshalBencode ¶
MarshalBencode returns the serialized byte slice representation of a contact.
func (Contact) MarshalCompact ¶
MarshalCompact returns a compact byteslice representation of the contact NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it
func (Contact) MarshalJSON ¶
func (*Contact) UnmarshalBencode ¶
UnmarshalBencode unmarshals the serialized byte slice into the appropriate fields of the contact.
func (*Contact) UnmarshalCompact ¶
UnmarshalCompact unmarshals the compact byteslice representation of a contact. NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it
type DHT ¶
type DHT struct {
// contains filtered or unexported fields
}
DHT represents a DHT node.
func New ¶
New returns a DHT pointer. If config is nil, then config will be set to the default config.
func (*DHT) Ping ¶
Ping pings a given address, creates a temporary contact for sending a message, and returns an error if communication fails.
func (*DHT) PrintState ¶
func (dht *DHT) PrintState()
PrintState prints the current state of the DHT including address, nr outstanding transactions, stored hashes as well as current bucket information.
func (*DHT) WaitUntilJoined ¶
func (dht *DHT) WaitUntilJoined()
WaitUntilJoined blocks until the node joins the network.
type Error ¶
Error represents a DHT error response
func (Error) MarshalBencode ¶
MarshalBencode returns the serialized byte slice representation of an error message.
func (*Error) UnmarshalBencode ¶
UnmarshalBencode unmarshals the serialized byte slice into the appropriate fields of the error message.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a type representation of a node on the network.
func (*Node) AddKnownNode ¶
AddKnownNode adds a known-good node to the routing table
func (*Node) Connect ¶
Connect connects to the given connection and starts any background threads necessary
func (*Node) CountActiveTransactions ¶
CountActiveTransactions returns the number of transactions in the manager
func (*Node) Send ¶
func (n *Node) Send(contact Contact, req Request, options ...SendOptions) *Response
Send sends a transaction and blocks until the response is available. It returns a response, or nil if the transaction timed out.
func (*Node) SendAsync ¶
func (n *Node) SendAsync(contact Contact, req Request, options ...SendOptions) <-chan *Response
SendAsync sends a transaction and returns a channel that will eventually contain the transaction response The response channel is closed when the transaction is completed or times out.
type Request ¶
type Request struct { ID messageID NodeID bits.Bitmap Method string Arg *bits.Bitmap StoreArgs *storeArgs ProtocolVersion int }
Request represents a DHT request message
func (Request) MarshalBencode ¶
MarshalBencode returns the serialized byte slice representation of the request
func (*Request) UnmarshalBencode ¶
UnmarshalBencode unmarshals the serialized byte slice into the appropriate fields of the request.
type RequestHandlerFunc ¶
RequestHandlerFunc is exported handler for requests.
type Response ¶
type Response struct { ID messageID NodeID bits.Bitmap Data string Contacts []Contact FindValueKey string Token string ProtocolVersion int Page uint8 }
Response represents a DHT response message
func (Response) MarshalBencode ¶
MarshalBencode returns the serialized byte slice representation of the response.
func (*Response) UnmarshalBencode ¶
UnmarshalBencode unmarshals the serialized byte slice into the appropriate fields of the store arguments.
type RpcBucketResponse ¶
type RpcFindValueResult ¶
type RpcIterativeFindValueArgs ¶
type RpcIterativeFindValueArgs struct {
Key string
}
type RpcPingArgs ¶
type RpcPingArgs struct {
Address string
}
type RpcRoutingTableResponse ¶
type RpcRoutingTableResponse struct { NodeID string NumBuckets int Buckets []RpcBucketResponse }
type SendOptions ¶
type SendOptions struct {
// contains filtered or unexported fields
}
SendOptions controls the behavior of send calls
type UDPConn ¶
type UDPConn interface { ReadFromUDP([]byte) (int, *net.UDPAddr, error) WriteToUDP([]byte, *net.UDPAddr) (int, error) SetReadDeadline(time.Time) error SetWriteDeadline(time.Time) error Close() error }
UDPConn allows using a mocked connection to test sending/receiving data TODO: stop mocking this and use the real thing