Documentation
¶
Overview ¶
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
// Copyright © 2019 Annchain Authors <EMAIL ADDRESS> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func CreateDB() (ogdb.Database, error)
- func ErrResp(code ErrCode, format string, v ...interface{}) error
- func GetOldDb() (ogdb.Database, error)
- func InitLoggers(logger *logrus.Logger, logdir string)
- type ControlMsgCache
- type DataLoader
- type EncryptionLayer
- type ErrCode
- type GetNodeDataMsgHandler
- type GetReceiptsMsgHandler
- type Hub
- func (h *Hub) AnonymousSendMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message, ...)
- func (h *Hub) BestPeerId() (peerId string, err error)
- func (h *Hub) BestPeerInfo() (peerId string, hash types.Hash, seqId uint64, err error)
- func (h *Hub) BroadcastMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
- func (h *Hub) BroadcastMessageWithFilter(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
- func (h *Hub) BroadcastMessageWithLink(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
- func (h *Hub) GetBenchmarks() map[string]interface{}
- func (h *Hub) GetPeerHead(peerId string) (hash types.Hash, seqId uint64, err error)
- func (h *Hub) Init(config *HubConfig)
- func (h *Hub) MulticastMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
- func (h *Hub) MulticastToSource(messageType message_archive.BinaryMessageType, msg p2p_message.Message, ...)
- func (h *Hub) Name() string
- func (h *Hub) NodeStatus() *NodeStatus
- func (h *Hub) PeersInfo() []*PeerInfo
- func (h *Hub) RelayMessage(msgOut *message_archive.types)
- func (h *Hub) RemovePeer(id string)
- func (h *Hub) RequestBodies(peerId string, hashs types.Hashes) error
- func (h *Hub) RequestOneHeader(peerId string, hash types.Hash) error
- func (h *Hub) SendBytesToPeer(peerId string, messageType message_archive.BinaryMessageType, msg []byte) error
- func (h *Hub) SendGetMsg(peerId string, msg *p2p_message.MessageGetMsg) error
- func (h *Hub) SendToPeer(messageType message_archive.BinaryMessageType, msg p2p_message.Message, ...) error
- func (h *Hub) SetEncryptionKey(priv *crypto.PrivateKey)
- func (h *Hub) SetPeerHead(peerId string, hash types.Hash, number uint64) error
- func (h *Hub) Start()
- func (h *Hub) Stop()
- type HubConfig
- type IncomingMessageHandler
- func (m *IncomingMessageHandler) GetBenchmarks() map[string]interface{}
- func (h *IncomingMessageHandler) HandleBodiesRequest(msgReq *p2p_message.MessageBodiesRequest, peerId string)
- func (h *IncomingMessageHandler) HandleBodiesResponse(request *p2p_message.MessageBodiesResponse, peerId string)
- func (h *IncomingMessageHandler) HandleControlMsg(req *p2p_message.MessageControl, sourceId string)
- func (h *IncomingMessageHandler) HandleFetchByHashRequest(syncRequest *p2p_message.MessageSyncRequest, peerId string)
- func (h *IncomingMessageHandler) HandleGetMsg(msg *p2p_message.MessageGetMsg, sourcePeerId string)
- func (h *IncomingMessageHandler) HandleHeaderRequest(query *p2p_message.MessageHeaderRequest, peerId string)
- func (h *IncomingMessageHandler) HandleHeaderResponse(headerMsg *p2p_message.MessageHeaderResponse, peerId string)
- func (h *IncomingMessageHandler) HandlePing(peerId string)
- func (h *IncomingMessageHandler) HandlePong()
- func (h *IncomingMessageHandler) HandleSequencerHeader(msgHeader *p2p_message.MessageSequencerHeader, peerId string)
- func (h *IncomingMessageHandler) HandleTxsRequest(msgReq *p2p_message.MessageTxsRequest, peerId string)
- func (h *IncomingMessageHandler) HandleTxsResponse(request *p2p_message.MessageTxsResponse)
- func (m *IncomingMessageHandler) Name() string
- func (h *IncomingMessageHandler) RemoveControlMsgFromCache(hash types2.Hash)
- func (m *IncomingMessageHandler) Start()
- func (m *IncomingMessageHandler) Stop()
- type IncomingMessageHandlerOG02
- type MessageRouterOG02
- type NodeDataMsgHandler
- type NodeStatus
- type OGConfig
- type Og
- type PeerInfo
- type PeerProvider
- type RequestCache
Constants ¶
const ( NormalMode uint8 = iota FeedBackMode )
const ( OG01 = 01 OG02 = 02 )
const ( ErrMsgTooLarge = iota ErrDecode ErrInvalidMsgCode ErrProtocolVersionMismatch ErrNetworkIdMismatch ErrGenesisBlockMismatch ErrNoStatusMsg ErrExtraStatusMsg ErrSuspendedPeer )
const (
DuplicateMsgPeerNum = 5
)
const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol Message
Variables ¶
var ProtocolName = "og"
ProtocolName is the official short name of the protocol used during capability negotiation.
var ProtocolVersions = []uint32{OG02, OG01}
ProtocolVersions are the supported versions of the og protocol (first is primary).
Functions ¶
func InitLoggers ¶
Types ¶
type ControlMsgCache ¶
msg request cache ,don't send duplicate Message
func (*ControlMsgCache) Len ¶
func (c *ControlMsgCache) Len() int
type DataLoader ¶
func (*DataLoader) GenerateGenesis ¶
func (d *DataLoader) GenerateGenesis() *types.Sequencer
func (*DataLoader) GenerateGenesisBalance ¶
func (loader *DataLoader) GenerateGenesisBalance() map[common.Address]*math.BigInt
func (*DataLoader) LoadLocalData ¶
func (d *DataLoader) LoadLocalData()
LoadLocalData will load all necessary Data (db, status, etc) from local database. If there is no Data or Data corrupted, rebuild.
func (*DataLoader) Name ¶
func (d *DataLoader) Name() string
func (*DataLoader) Start ¶
func (d *DataLoader) Start()
func (*DataLoader) Stop ¶
func (d *DataLoader) Stop()
type EncryptionLayer ¶
type EncryptionLayer interface {
SetEncryptionKey(priv *crypto.PrivateKey)
}
type GetNodeDataMsgHandler ¶
type GetNodeDataMsgHandler interface {
HandleGetNodeDataMsg(peerId string)
}
type GetReceiptsMsgHandler ¶
type GetReceiptsMsgHandler interface {
HandleGetReceiptsMsg(peerId string)
}
type Hub ¶
type Hub struct { //CallbackRegistry map[message.BinaryMessageType]func(*message.types) // All callbacks //CallbackRegistryOG02 map[message.BinaryMessageType]func(*message.types) // All callbacks of OG02 StatusDataProvider NodeStatusDataProvider SubProtocols []p2p.Protocol // new peer event OnNewPeerConnected []chan string Downloader *downloader.Downloader Fetcher *fetcher.Fetcher NodeInfo func() *p2p.NodeInfo IsReceivedHash func(hash types.Hash) bool MessageUnmarshaller message_archive.typesUnmarshalManager // contains filtered or unexported fields }
Hub is the middle layer between p2p and business layer When there is a general request coming from the upper layer, Hub will find the appropriate peer to handle. When there is a Message coming from p2p, Hub will unmarshall this Message and give it to Message router. Hub will also prevent duplicate requests/responses. If there is any failure, Hub is NOT responsible for changing a peer and retry. (maybe enhanced in the future.) DO NOT INVOLVE ANY BUSINESS LOGICS HERE.
func (*Hub) AnonymousSendMessage ¶ added in v0.0.7
func (h *Hub) AnonymousSendMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message, encryptionKey *crypto.PublicKey)
AnonymousSendMessage use a pubkey to encrypt the Message and then broadcast it Only the one who has the private key can decrypt the Message and become the receiver. the Message will append the target receiver pubkey to accelerate filtering on the target side. TODO: support multi encryption keys in one Message TODO: encrypt the Message whatever disableEncryptGossip is on or not
func (*Hub) BestPeerId ¶
func (*Hub) BestPeerInfo ¶
func (*Hub) BroadcastMessage ¶
func (h *Hub) BroadcastMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
BroadcastMessage broadcast to whole network
func (*Hub) BroadcastMessageWithFilter ¶
func (h *Hub) BroadcastMessageWithFilter(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
BroadcastMessage broadcast to whole network
func (*Hub) BroadcastMessageWithLink ¶
func (h *Hub) BroadcastMessageWithLink(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
BroadcastMessage broadcast to whole network
func (*Hub) GetBenchmarks ¶
func (*Hub) GetPeerHead ¶
func (*Hub) MulticastMessage ¶
func (h *Hub) MulticastMessage(messageType message_archive.BinaryMessageType, msg p2p_message.Message)
MulticastMessage multicast Message to some peer
func (*Hub) MulticastToSource ¶
func (h *Hub) MulticastToSource(messageType message_archive.BinaryMessageType, msg p2p_message.Message, sourceMsgHash *types.Hash)
MulticastToSource multicast msg to source , for example , send tx request to the peer which Hash the tx
func (*Hub) NodeStatus ¶
func (h *Hub) NodeStatus() *NodeStatus
NodeInfo retrieves some protocol metadata about the running host node.
func (*Hub) RelayMessage ¶
func (h *Hub) RelayMessage(msgOut *message_archive.types)
func (*Hub) RemovePeer ¶
func (*Hub) SendBytesToPeer ¶
func (h *Hub) SendBytesToPeer(peerId string, messageType message_archive.BinaryMessageType, msg []byte) error
func (*Hub) SendGetMsg ¶
func (h *Hub) SendGetMsg(peerId string, msg *p2p_message.MessageGetMsg) error
func (*Hub) SendToPeer ¶
func (h *Hub) SendToPeer(messageType message_archive.BinaryMessageType, msg p2p_message.Message, peerId string) error
func (*Hub) SetEncryptionKey ¶
func (h *Hub) SetEncryptionKey(priv *crypto.PrivateKey)
func (*Hub) SetPeerHead ¶
SetPeerHead is just a hack to set the latest seq number known of the peer This value ought not to be stored in peer, but an outside map. This has nothing related to p2p.
type HubConfig ¶
type HubConfig struct { OutgoingBufferSize int IncomingBufferSize int MessageCacheMaxSize int MessageCacheExpirationSeconds int MaxPeers int BroadCastMode uint8 DisableEncryptGossip bool }
func DefaultHubConfig ¶
func DefaultHubConfig() HubConfig
type IncomingMessageHandler ¶
type IncomingMessageHandler struct { Og *Og Hub *Hub TxEnable func() bool // contains filtered or unexported fields }
IncomingMessageHandler is the default handler of all incoming messages for OG
func NewIncomingMessageHandler ¶
func NewIncomingMessageHandler(og *Og, hub *Hub, cacheSize int, expireTime time.Duration) *IncomingMessageHandler
NewIncomingMessageHandler
func (*IncomingMessageHandler) GetBenchmarks ¶
func (m *IncomingMessageHandler) GetBenchmarks() map[string]interface{}
func (*IncomingMessageHandler) HandleBodiesRequest ¶
func (h *IncomingMessageHandler) HandleBodiesRequest(msgReq *p2p_message.MessageBodiesRequest, peerId string)
func (*IncomingMessageHandler) HandleBodiesResponse ¶
func (h *IncomingMessageHandler) HandleBodiesResponse(request *p2p_message.MessageBodiesResponse, peerId string)
func (*IncomingMessageHandler) HandleControlMsg ¶
func (h *IncomingMessageHandler) HandleControlMsg(req *p2p_message.MessageControl, sourceId string)
func (*IncomingMessageHandler) HandleFetchByHashRequest ¶
func (h *IncomingMessageHandler) HandleFetchByHashRequest(syncRequest *p2p_message.MessageSyncRequest, peerId string)
func (*IncomingMessageHandler) HandleGetMsg ¶
func (h *IncomingMessageHandler) HandleGetMsg(msg *p2p_message.MessageGetMsg, sourcePeerId string)
func (*IncomingMessageHandler) HandleHeaderRequest ¶
func (h *IncomingMessageHandler) HandleHeaderRequest(query *p2p_message.MessageHeaderRequest, peerId string)
func (*IncomingMessageHandler) HandleHeaderResponse ¶
func (h *IncomingMessageHandler) HandleHeaderResponse(headerMsg *p2p_message.MessageHeaderResponse, peerId string)
func (*IncomingMessageHandler) HandlePing ¶
func (h *IncomingMessageHandler) HandlePing(peerId string)
func (*IncomingMessageHandler) HandlePong ¶
func (h *IncomingMessageHandler) HandlePong()
func (*IncomingMessageHandler) HandleSequencerHeader ¶
func (h *IncomingMessageHandler) HandleSequencerHeader(msgHeader *p2p_message.MessageSequencerHeader, peerId string)
func (*IncomingMessageHandler) HandleTxsRequest ¶
func (h *IncomingMessageHandler) HandleTxsRequest(msgReq *p2p_message.MessageTxsRequest, peerId string)
func (*IncomingMessageHandler) HandleTxsResponse ¶
func (h *IncomingMessageHandler) HandleTxsResponse(request *p2p_message.MessageTxsResponse)
func (*IncomingMessageHandler) Name ¶
func (m *IncomingMessageHandler) Name() string
func (*IncomingMessageHandler) RemoveControlMsgFromCache ¶
func (h *IncomingMessageHandler) RemoveControlMsgFromCache(hash types2.Hash)
func (*IncomingMessageHandler) Start ¶
func (m *IncomingMessageHandler) Start()
func (*IncomingMessageHandler) Stop ¶
func (m *IncomingMessageHandler) Stop()
type IncomingMessageHandlerOG02 ¶
IncomingMessageHandler is the default handler of all incoming messages for OG
func (*IncomingMessageHandlerOG02) HandleGetNodeDataMsg ¶
func (h *IncomingMessageHandlerOG02) HandleGetNodeDataMsg(peerId string)
func (*IncomingMessageHandlerOG02) HandleGetReceiptsMsg ¶
func (h *IncomingMessageHandlerOG02) HandleGetReceiptsMsg(peerId string)
func (*IncomingMessageHandlerOG02) HandleNodeDataMsg ¶
func (h *IncomingMessageHandlerOG02) HandleNodeDataMsg(peerId string)
type MessageRouterOG02 ¶
type MessageRouterOG02 struct { GetNodeDataMsgHandler GetNodeDataMsgHandler NodeDataMsgHandler NodeDataMsgHandler GetReceiptsMsgHandler GetReceiptsMsgHandler }
func (*MessageRouterOG02) Name ¶
func (m *MessageRouterOG02) Name() string
func (*MessageRouterOG02) RouteGetNodeDataMsg ¶
func (m *MessageRouterOG02) RouteGetNodeDataMsg(msg *types)
func (*MessageRouterOG02) RouteGetReceiptsMsg ¶
func (m *MessageRouterOG02) RouteGetReceiptsMsg(msg *types)
func (*MessageRouterOG02) RouteNodeDataMsg ¶
func (m *MessageRouterOG02) RouteNodeDataMsg(msg *types)
func (*MessageRouterOG02) Start ¶
func (m *MessageRouterOG02) Start()
func (*MessageRouterOG02) Stop ¶
func (m *MessageRouterOG02) Stop()
type NodeDataMsgHandler ¶
type NodeDataMsgHandler interface {
HandleNodeDataMsg(peerId string)
}
type NodeStatus ¶
type NodeStatus struct { Network uint64 `json:"network"` // OG network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4) Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain Genesis types.Hash `json:"genesis"` // SHA3 Hash of the host's genesis block Head types.Hash `json:"head"` // SHA3 Hash of the host's best owned block }
NodeInfo represents a short summary of the OG sub-protocol metadata known about the host peer.
type OGConfig ¶
func DefaultOGConfig ¶
func DefaultOGConfig() OGConfig
type Og ¶
type Og struct { Dag *core2.Dag TxPool *pool.TxPool Manager *MessageRouter TxBuffer *pool.TxBuffer NewLatestSequencerCh chan bool //for broadcasting new latest sequencer to record height NetworkId uint64 // contains filtered or unexported fields }
func (*Og) BroadcastLatestSequencer ¶
func (og *Og) BroadcastLatestSequencer()
BroadcastLatestSequencer broadcast the newest sequencer header , seuqencer header is a network state , representing peer's height other peers will know our height and know whether thy were updated and sync with the best height
func (*Og) GetCurrentOgStatus ¶ added in v0.0.7
func (og *Og) GetCurrentOgStatus() model.OgStatusData
type PeerInfo ¶
type PeerInfo struct { Version int `json:"Version"` // Ethereum protocol Version negotiated SequencerId uint64 `json:"sequencer_id"` // Total difficulty of the peer's blockchain Head string `json:"head"` // SHA3 Hash of the peer's best owned block ShortId string `json:"short_id"` Link bool `json:"link"` Addrs string `json:"addrs"` InBound bool `json:"in_bound"` }
type PeerProvider ¶
type RequestCache ¶
type RequestCache struct {
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package fetcher contains the sequencer announcement based synchronisation.
|
Package fetcher contains the sequencer announcement based synchronisation. |
protocol
|
|
ogmessage/archive
// Copyright © 2019 Annchain Authors <EMAIL ADDRESS> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.
|
// Copyright © 2019 Annchain Authors <EMAIL ADDRESS> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. |