Documentation ¶
Index ¶
- Constants
- func CompareDistance(target, a, b common.Hash) int
- func IsReserveIP(ip net.IP) bool
- func LogDistance(a, b common.Hash) int
- func NodeID2PublicKey(nodeID NodeID) (*ecdsa.PublicKey, error)
- type AESEncryptKey
- type AuthRequest
- type AuthResponse
- type Bucket
- type ClosestNodeSet
- type Endpoint
- type FindNodeMessage
- type GenericMessage
- type MConnection
- type Message
- type MessageConn
- type MessageHandler
- type MessageReader
- type MessageWriter
- type NeighborsMessage
- type NetworkManager
- type Node
- type NodeDB
- type NodeID
- type NodeMessage
- type P2PServer
- type Peer
- func (p *Peer) GetID() NodeID
- func (p *Peer) MarkBlock(hash common.Hash)
- func (p *Peer) MarkTransaction(hash common.Hash)
- func (p *Peer) PerformHandshake(network, version string, genesis common.Hash) error
- func (p *Peer) ReadMessage() (*Message, error)
- func (p *Peer) SendBlock(block *model.Block) error
- func (p *Peer) SendTransactions(transactions []*model.Transaction) error
- func (p *Peer) StartRunning()
- func (p *Peer) WriteMessage(message *Message) error
- type PeerDialer
- type PeerManager
- type PeerState
- type PingMessage
- type PongMessage
- type ProtocolMessageHandler
- type RouterTable
- func (table *RouterTable) AddNode(node *Node)
- func (table *RouterTable) DeleteNode(node *Node)
- func (table *RouterTable) ExistNodeInTable(nodeID NodeID) bool
- func (table *RouterTable) GetClosestNodes(nodeID NodeID) *ClosestNodeSet
- func (table *RouterTable) GetRandomNodeList(size int) []*Node
- func (table *RouterTable) InjectNodes(nodes []*Node)
- func (table *RouterTable) StartRefresh()
- type Secret
Constants ¶
View Source
const ( NewBlockResp = "newBlockResp" TransactionsResp = "transactionsResp" PeerStateReq = "peerStateReq" PeerStateResp = "peerStateResp" BlockHeadersReq = "blockHeadersReq" BlockHeadersResp = "blockHeadersResp" BlockBodiesReq = "blockBodiesReq" BlockBodiesResp = "blockBodiesResp" NodeDataReq = "nodeDataReq" NodeDataResp = "nodeDataResp" ReceiptsReq = "receiptReq" ReceiptsResp = "receiptsResp" )
View Source
const ( UDP = "udp" TCP = "tcp" BufferSize = 1280 Expiration = 20 * time.Second )
View Source
const ( Ping = "ping" Pong = "pong" FindNode = "findNode" Neighbors = "neighbors" )
View Source
const ( AuthRequestLength = 1024 AuthResponseLength = 1024 )
View Source
const ( MaxKnownBlocks = 1024 MaxKnownTransactions = 32768 )
View Source
const ( BucketCount = 256 BucketSize = 16 )
View Source
const (
AESKeyLength = 32
)
View Source
const (
DefaultDialTimeout = 15 * time.Second
)
View Source
const (
EncryptEchoMessage = "Received AES Encrypt Key"
)
View Source
const (
MaxMessageSize = ^uint32(0) >> 8
)
View Source
const (
MaxNeighborsCount = 8
)
View Source
const (
NodeIDLength = 64
)
Variables ¶
This section is empty.
Functions ¶
func CompareDistance ¶
func IsReserveIP ¶
func LogDistance ¶
Types ¶
type AESEncryptKey ¶
type AESEncryptKey []byte
type AuthRequest ¶
type AuthRequest struct {
// contains filtered or unexported fields
}
func NewAuthRequest ¶
func NewAuthRequest(remoteNodeID NodeID, aesEncryptKey AESEncryptKey) *AuthRequest
type AuthResponse ¶
type AuthResponse struct {
// contains filtered or unexported fields
}
func NewAuthResponse ¶
func NewAuthResponse(selfNodeID, remoteNodeID NodeID, echoMessage string) *AuthResponse
type ClosestNodeSet ¶
type ClosestNodeSet struct { TargetHash common.Hash ClosestNodes [BucketSize]*Node }
func (*ClosestNodeSet) AcceptNode ¶
func (set *ClosestNodeSet) AcceptNode(node *Node)
type FindNodeMessage ¶
type FindNodeMessage struct { GenericMessage Target NodeID `json:"targetNodeID"` }
func NewFindNodeMessage ¶
func NewFindNodeMessage(selfNodeID NodeID, targetNodeID NodeID) *FindNodeMessage
func (*FindNodeMessage) InitMessage ¶
func (msg *FindNodeMessage) InitMessage() error
type GenericMessage ¶
type GenericMessage struct { NodeID NodeID `json:"nodeID"` MessageType string `json:"messageType"` Signature string `json:"signature"` Expiration int64 `json:"expiration"` MessageHash common.Hash `json:"messageHash"` }
func (*GenericMessage) GetExpiration ¶
func (gm *GenericMessage) GetExpiration() int64
func (*GenericMessage) GetMessageHash ¶
func (gm *GenericMessage) GetMessageHash() common.Hash
func (*GenericMessage) GetMessageType ¶
func (gm *GenericMessage) GetMessageType() string
func (*GenericMessage) GetNodeID ¶
func (gm *GenericMessage) GetNodeID() NodeID
func (*GenericMessage) GetSignature ¶
func (gm *GenericMessage) GetSignature() string
type MConnection ¶
type MConnection struct {
// contains filtered or unexported fields
}
func (*MConnection) Read ¶
func (conn *MConnection) Read() (*Message, error)
func (*MConnection) Write ¶
func (conn *MConnection) Write(message *Message) error
type Message ¶
type Message struct { MessageType string `json:"type"` MessageBody interface{} `json:"body"` }
func (*Message) UnmarshalJSON ¶
type MessageConn ¶
type MessageConn interface { MessageReader MessageWriter }
func NewMConnection ¶
func NewMConnection(conn net.Conn, secret *Secret) MessageConn
type MessageHandler ¶
type MessageHandler struct {
// contains filtered or unexported fields
}
func NewMessageHandler ¶
func NewMessageHandler(manager *NetworkManager) *MessageHandler
type MessageReader ¶
type MessageWriter ¶
type NeighborsMessage ¶
type NeighborsMessage struct { GenericMessage NodeList []Endpoint }
func NewNeighborsMessage ¶
func NewNeighborsMessage(selfNodeID NodeID, nodeList []Endpoint) *NeighborsMessage
func (*NeighborsMessage) InitMessage ¶
func (msg *NeighborsMessage) InitMessage() error
type NetworkManager ¶
type NetworkManager struct { NetworkConfig config.NetworkConfig RouterTable *RouterTable UDPConn *net.UDPConn Dialer *net.Dialer SelfNode Node MessageHandler *MessageHandler }
func NewNetworkManager ¶
func NewNetworkManager(config config.Config) (*NetworkManager, error)
func (*NetworkManager) Start ¶
func (nm *NetworkManager) Start() error
type Node ¶
type NodeMessage ¶
type P2PServer ¶
type P2PServer struct {
// contains filtered or unexported fields
}
func NewP2PServer ¶
func NewP2PServer(config config.Config, peerManager *PeerManager) (*P2PServer, error)
func (*P2PServer) StartServer ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func NewPeer ¶
func NewPeer(nodeID NodeID, connection MessageConn) *Peer
func (*Peer) MarkTransaction ¶
func (*Peer) PerformHandshake ¶
func (*Peer) ReadMessage ¶
func (*Peer) SendTransactions ¶
func (p *Peer) SendTransactions(transactions []*model.Transaction) error
func (*Peer) StartRunning ¶
func (p *Peer) StartRunning()
func (*Peer) WriteMessage ¶
type PeerDialer ¶
type PeerDialer struct {
// contains filtered or unexported fields
}
func NewPeerDialer ¶
func NewPeerDialer() *PeerDialer
func (*PeerDialer) StartDialing ¶
func (pd *PeerDialer) StartDialing() error
type PeerManager ¶
type PeerManager struct {
// contains filtered or unexported fields
}
func NewPeerManager ¶
func NewPeerManager(config config.SyncConfig) *PeerManager
func (*PeerManager) AddPeer ¶
func (pm *PeerManager) AddPeer(peer *Peer)
func (*PeerManager) BroadcastTransaction ¶
func (pm *PeerManager) BroadcastTransaction(tx *model.Transaction) error
func (*PeerManager) RemovePeer ¶
func (pm *PeerManager) RemovePeer(peerId NodeID)
func (*PeerManager) SetProtocolHandler ¶
func (pm *PeerManager) SetProtocolHandler(messageHandler ProtocolMessageHandler)
type PingMessage ¶
type PingMessage struct { GenericMessage Source Endpoint Destination Endpoint }
func NewPingMessage ¶
func NewPingMessage(selfNodeID NodeID, sourceAddress, destinationAddress *net.UDPAddr) *PingMessage
func (*PingMessage) InitMessage ¶
func (msg *PingMessage) InitMessage() error
type PongMessage ¶
type PongMessage struct { GenericMessage Destination Endpoint ReplyData common.Hash }
func (*PongMessage) InitMessage ¶
func (msg *PongMessage) InitMessage() error
type ProtocolMessageHandler ¶
type RouterTable ¶
type RouterTable struct {
// contains filtered or unexported fields
}
func NewRouterTable ¶
func NewRouterTable(self *Node) *RouterTable
func (*RouterTable) AddNode ¶
func (table *RouterTable) AddNode(node *Node)
func (*RouterTable) DeleteNode ¶
func (table *RouterTable) DeleteNode(node *Node)
func (*RouterTable) ExistNodeInTable ¶
func (table *RouterTable) ExistNodeInTable(nodeID NodeID) bool
func (*RouterTable) GetClosestNodes ¶
func (table *RouterTable) GetClosestNodes(nodeID NodeID) *ClosestNodeSet
func (*RouterTable) GetRandomNodeList ¶
func (table *RouterTable) GetRandomNodeList(size int) []*Node
func (*RouterTable) InjectNodes ¶
func (table *RouterTable) InjectNodes(nodes []*Node)
func (*RouterTable) StartRefresh ¶
func (table *RouterTable) StartRefresh()
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
func NewSecretWithAESKey ¶
func NewSecretWithAESKey(remoteNodeID NodeID, localPrivateKey *ecdsa.PrivateKey, remotePublicKey *ecdsa.PublicKey, aesEncryptKey AESEncryptKey) (*Secret, error)
Click to show internal directories.
Click to hide internal directories.