Documentation
¶
Index ¶
- func GetFromCache(domain string) (string, bool)
- func NodesCleanup(nodes []*Node)
- func ResolveDomain(domain string, n *Node) (string, error)
- func SetToCache(domain, ip string)
- func StartDNSServer(port string, node *Node)
- type BDNSRequest
- type BDNSResponse
- type DNSRecord
- type GossipMessage
- type Message
- type MessageType
- type Node
- func (n *Node) AddBlock(block *blockchain.Block)
- func (n *Node) AddTransaction(tx *blockchain.Transaction)
- func (n *Node) BroadcastRandomNumber(epoch int64)
- func (n *Node) BroadcastTransaction(tx blockchain.Transaction)
- func (n *Node) ChooseTxFromPool(limit int) []blockchain.Transaction
- func (n *Node) CreateBlockIfLeader()
- func (n *Node) DNSRequestHandler(req BDNSRequest, reqSender string, metrics *metrics.DNSMetrics)
- func (n *Node) DNSResponseHandler(res BDNSResponse)
- func (n *Node) GenerateRandomNumber() []byte
- func (n *Node) GetSlotLeader(epoch int64) []byte
- func (n *Node) HandleGetBlock(sender string)
- func (n *Node) HandleGetData(sender string)
- func (n *Node) HandleGossip()
- func (n *Node) HandleINV(sender string)
- func (n *Node) HandleMerkleRequest(sender string)
- func (n *Node) HandleMsgGivenType(msg GossipMessage, _ *metrics.DNSMetrics)
- func (n *Node) InitializeNodeAsync(chainID string, registryKeys [][]byte, initialTimestamp int64, ...)
- func (n *Node) ListenForDirectMessages()
- func (n *Node) MakeDNSRequest(domainName string, metrics *metrics.DNSMetrics)
- func (n *Node) RandomNumberHandler(epoch int64, sender string, secretValue int, randomValue int)
- type NodeConfig
- type P2PNetwork
- func (p *P2PNetwork) BroadcastMessage(msgType MessageType, content interface{}, metrics *metrics.DNSMetrics)
- func (p *P2PNetwork) Close()
- func (p *P2PNetwork) ConnectToPeer(peerAddr string) error
- func (p *P2PNetwork) DirectMessage(msgType MessageType, content interface{}, peerIDStr string)
- func (p *P2PNetwork) ListenForGossip()
- type RandomNumberMsg
- type RecordType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFromCache ¶
Get retrieves a domain from the cache
func NodesCleanup ¶
func NodesCleanup(nodes []*Node)
func ResolveDomain ¶
ResolveDomain queries the BDNS blockchain for a domain
func SetToCache ¶
func SetToCache(domain, ip string)
Set stores a domain in the cache with a default TTL of 300 seconds
func StartDNSServer ¶
StartDNSServer initializes and starts a UDP-based DNS server
Types ¶
type BDNSRequest ¶
type BDNSRequest struct {
DomainName string
}
type BDNSResponse ¶
type DNSRecord ¶
type DNSRecord struct {
DomainName string `json:"domain"` // The domain being registered
RecordType RecordType `json:"type"` // The type of DNS record
Value string `json:"value"` // IP, alias, mail server, or other value
TTL int64 `json:"ttl"` // Time-To-Live in seconds
Priority int `json:"priority"` // Used for MX/SRV records
Port int `json:"port"` // Used for SRV records
OwnerKey string `json:"ownerKey"` // Owner's public key
Signature string `json:"signature"` // Signature to verify authenticity
Timestamp int64 `json:"timestamp"` // Record creation time
}
DNSRecord represents a BDNS record stored in the blockchain
type GossipMessage ¶
type GossipMessage struct {
Type MessageType
Sender string // Peer ID
Content json.RawMessage
Metrics *metrics.DNSMetrics
}
GossipMessage structure
type Message ¶
type Message struct {
Sender string `json:"sender"`
Type MessageType `json:"type"`
Data []byte `json:"data"`
}
Message represents a generic network message
type MessageType ¶
type MessageType string
MessageType defines various message types in the P2P network
const ( DNSRequest MessageType = "DNS_REQUEST" DNSResponse MessageType = "DNS_RESPONSE" MsgTransaction MessageType = "TRANSACTION" MsgBlock MessageType = "BLOCK" MsgChainRequest MessageType = "CHAIN_REQUEST" MsgChainResponse MessageType = "CHAIN_RESPONSE" MsgPeerRequest MessageType = "PEER_REQUEST" MsgPeerResponse MessageType = "PEER_RESPONSE" MsgRandomNumber MessageType = "RANDOM_NUMBER" MsgInv MessageType = "INV" MsgGetBlock MessageType = "GET_BLOCK" MsgGetData MessageType = "GET_DATA" MsgGetMerkle MessageType = "GET_MERKLE" )
type Node ¶
type Node struct {
Address string
Port int
Config NodeConfig
P2PNetwork *P2PNetwork
KeyPair *blockchain.KeyPair
RegistryKeys [][]byte
SlotLeaders map[int64][]byte // epoch to slot leader
SlotMutex sync.Mutex
TransactionPool map[int]*blockchain.Transaction
TxMutex sync.Mutex
IndexManager *index.IndexManager
Blockchain *blockchain.Blockchain
BcMutex sync.Mutex
RandomNumber []byte
RandomMutex sync.Mutex
EpochRandoms map[int64]map[string]consensus.SecretValues
IsFullNode bool // full vs light node
PeerID string
KnownFullPeers []string
}
Node represents a blockchain peer
func InitializeP2PNodes ¶
func (*Node) AddBlock ¶
func (n *Node) AddBlock(block *blockchain.Block)
func (*Node) AddTransaction ¶
func (n *Node) AddTransaction(tx *blockchain.Transaction)
func (*Node) BroadcastRandomNumber ¶
func (*Node) BroadcastTransaction ¶
func (n *Node) BroadcastTransaction(tx blockchain.Transaction)
func (*Node) ChooseTxFromPool ¶
func (n *Node) ChooseTxFromPool(limit int) []blockchain.Transaction
func (*Node) CreateBlockIfLeader ¶
func (n *Node) CreateBlockIfLeader()
func (*Node) DNSRequestHandler ¶
func (n *Node) DNSRequestHandler(req BDNSRequest, reqSender string, metrics *metrics.DNSMetrics)
func (*Node) DNSResponseHandler ¶
func (n *Node) DNSResponseHandler(res BDNSResponse)
func (*Node) GenerateRandomNumber ¶
func (*Node) GetSlotLeader ¶
func (*Node) HandleGetBlock ¶
HandleGetBlock responds with full blockchain blocks starting from a given height
func (*Node) HandleGetData ¶
HandleGetData responds with transactions in the mempool
func (*Node) HandleGossip ¶
func (n *Node) HandleGossip()
HandleGossip listens for messages from the gossip network
func (*Node) HandleMerkleRequest ¶
HandleMerkleRequest sends Merkle proof path for a record
func (*Node) HandleMsgGivenType ¶
func (n *Node) HandleMsgGivenType(msg GossipMessage, _ *metrics.DNSMetrics)
func (*Node) InitializeNodeAsync ¶
func (*Node) ListenForDirectMessages ¶
func (n *Node) ListenForDirectMessages()
Handles direct peer-to-peer messages
func (*Node) MakeDNSRequest ¶
func (n *Node) MakeDNSRequest(domainName string, metrics *metrics.DNSMetrics)
type NodeConfig ¶
type NodeConfig struct {
InitialTimestamp int64
SlotInterval int64
SlotsPerEpoch int64
Seed float64
}
Node Config
type P2PNetwork ¶
type P2PNetwork struct {
Host host.Host
PubSub *pubsub.PubSub
Topic *pubsub.Topic
Sub *pubsub.Subscription
MsgChan chan GossipMessage
}
P2PNetwork struct manages libp2p host and pubsub
func NewP2PNetwork ¶
NewP2PNetwork initializes a libp2p node with pubsub gossip
func (*P2PNetwork) BroadcastMessage ¶
func (p *P2PNetwork) BroadcastMessage(msgType MessageType, content interface{}, metrics *metrics.DNSMetrics)
BroadcastMessage publishes a message to the gossip network
func (*P2PNetwork) ConnectToPeer ¶
func (p *P2PNetwork) ConnectToPeer(peerAddr string) error
ConnectToPeer connects to another peer via multiaddress
func (*P2PNetwork) DirectMessage ¶
func (p *P2PNetwork) DirectMessage(msgType MessageType, content interface{}, peerIDStr string)
DirectMessage sends a message to a specific peer
func (*P2PNetwork) ListenForGossip ¶
func (p *P2PNetwork) ListenForGossip()
ListenForGossip listens for gossip messages
type RandomNumberMsg ¶
type RecordType ¶
type RecordType string
RecordType defines supported BDNS record types
const ( A RecordType = "A" // IPv4 Address AAAA RecordType = "AAAA" // IPv6 Address CNAME RecordType = "CNAME" // Alias for another domain MX RecordType = "MX" // Mail Exchange )