Documentation
¶
Overview ¶
Package dht provides decentralized server discovery using LibP2P Kademlia DHT.
Package dht provides decentralized server discovery using LibP2P Kademlia DHT.
Package dht provides decentralized server discovery using LibP2P Kademlia DHT.
Index ¶
- Constants
- func NewValidator() record.NamespacedValidator
- type Bootstrapper
- type Config
- type Node
- func (n *Node) Addrs() []multiaddr.Multiaddr
- func (n *Node) AnnounceServer(ctx context.Context, record ServerRecord) error
- func (n *Node) Close() error
- func (n *Node) LookupServer(ctx context.Context, serverName string) (*ServerRecord, error)
- func (n *Node) PeerCount() int
- func (n *Node) PeerID() peer.ID
- func (n *Node) QueryServers(ctx context.Context, genre string, maxResults int) ([]*ServerRecord, error)
- func (n *Node) Routing() routing.Routing
- func (n *Node) UpdateGenreIndex(ctx context.Context, genre, serverName string, add bool) error
- type NodeInterface
- type ServerRecord
- type ViolenceValidator
Constants ¶
const ( // RecordTTL is the time-to-live for DHT records (8 hours) RecordTTL = 8 * time.Hour // MinReplicas is the minimum number of replicas per DHT record MinReplicas = 3 // BootstrapTimeout is the max time to wait for bootstrap BootstrapTimeout = 30 * time.Second )
const (
// ViolenceNamespace is the DHT namespace for Violence server records
ViolenceNamespace = "violence"
)
Variables ¶
This section is empty.
Functions ¶
func NewValidator ¶
func NewValidator() record.NamespacedValidator
NewValidator creates a namespaced validator for Violence records.
Types ¶
type Bootstrapper ¶
Bootstrap connects to the default IPFS bootstrap peers so the node can join the global DHT network. Callers that only need local connectivity should pass an empty bootstrap list in Config instead.
type Config ¶
type Config struct {
// ListenAddrs are the multiaddrs to listen on (e.g., "/ip4/0.0.0.0/tcp/0")
ListenAddrs []string
// BootstrapPeers are known DHT bootstrap nodes
BootstrapPeers []string
// Mode is either "server" or "client" (affects DHT mode)
Mode string
}
Config holds configuration for DHT node creation.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a DHT node for peer-to-peer server discovery.
func (*Node) AnnounceServer ¶
func (n *Node) AnnounceServer(ctx context.Context, record ServerRecord) error
AnnounceServer publishes a server record to the DHT. The record will be replicated across at least MinReplicas peers.
func (*Node) LookupServer ¶
LookupServer retrieves a server record from the DHT by name.
func (*Node) QueryServers ¶
func (n *Node) QueryServers(ctx context.Context, genre string, maxResults int) ([]*ServerRecord, error)
QueryServers searches for servers matching the given genre. Returns up to maxResults servers.
type NodeInterface ¶
type NodeInterface interface {
// Close shuts down the node and releases all resources.
Close() error
// PeerID returns the local peer ID.
PeerID() peer.ID
// Addrs returns the listen addresses for this node.
Addrs() []multiaddr.Multiaddr
// Routing returns the underlying routing.Routing implementation.
Routing() routing.Routing
// PeerCount returns the number of currently connected peers.
PeerCount() int
}
NodeInterface abstracts the DHT node so that callers can be tested without creating a live libp2p host.
type ServerRecord ¶
type ServerRecord struct {
Name string `json:"name"`
Address string `json:"address"`
Genre string `json:"genre"`
MaxPlayers int `json:"maxPlayers"`
Uptime int64 `json:"uptime"` // seconds
Timestamp time.Time `json:"timestamp"`
}
ServerRecord represents a server announcement stored in the DHT.
type ViolenceValidator ¶
type ViolenceValidator struct{}
ViolenceValidator validates Violence DHT records.