og

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

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

View Source
const (
	NormalMode uint8 = iota
	FeedBackMode
)
View Source
const (
	OG01 = 01
	OG02 = 02
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
)
View Source
const (
	DuplicateMsgPeerNum = 5
)
View Source
const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol Message

Variables

View Source
var ProtocolName = "og"

ProtocolName is the official short name of the protocol used during capability negotiation.

View Source
var ProtocolVersions = []uint32{OG02, OG01}

ProtocolVersions are the supported versions of the og protocol (first is primary).

Functions

func CreateDB

func CreateDB() (ogdb.Database, error)

func ErrResp added in v0.0.7

func ErrResp(code ErrCode, format string, v ...interface{}) error

func GetOldDb

func GetOldDb() (ogdb.Database, error)

func InitLoggers

func InitLoggers(logger *logrus.Logger, logdir string)

Types

type ControlMsgCache

type ControlMsgCache struct {
	ExpireTime time.Duration
	// contains filtered or unexported fields
}

msg request cache ,don't send duplicate Message

func (*ControlMsgCache) Len

func (c *ControlMsgCache) Len() int

type DataLoader

type DataLoader struct {
	Dag    *core2.Dag
	TxPool *pool.TxPool
}

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 ErrCode added in v0.0.7

type ErrCode int

func (ErrCode) String added in v0.0.7

func (e ErrCode) String() string

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 NewHub

func NewHub(config *HubConfig) *Hub

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 (h *Hub) BestPeerId() (peerId string, err error)

func (*Hub) BestPeerInfo

func (h *Hub) BestPeerInfo() (peerId string, hash types.Hash, seqId uint64, err error)

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 (h *Hub) BroadcastMessageWithLink(messageType message_archive.BinaryMessageType, msg p2p_message.Message)

BroadcastMessage broadcast to whole network

func (*Hub) GetBenchmarks

func (h *Hub) GetBenchmarks() map[string]interface{}

func (*Hub) GetPeerHead

func (h *Hub) GetPeerHead(peerId string) (hash types.Hash, seqId uint64, err error)

func (*Hub) Init

func (h *Hub) Init(config *HubConfig)

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) Name

func (h *Hub) Name() string

func (*Hub) NodeStatus

func (h *Hub) NodeStatus() *NodeStatus

NodeInfo retrieves some protocol metadata about the running host node.

func (*Hub) PeersInfo

func (h *Hub) PeersInfo() []*PeerInfo

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 (h *Hub) RemovePeer(id string)

func (*Hub) RequestBodies

func (h *Hub) RequestBodies(peerId string, hashs types.Hashes) error

func (*Hub) RequestOneHeader

func (h *Hub) RequestOneHeader(peerId string, hash types.Hash) error

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

func (h *Hub) SetPeerHead(peerId string, hash types.Hash, number uint64) error

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.

func (*Hub) Start

func (h *Hub) Start()

func (*Hub) Stop

func (h *Hub) Stop()

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

type IncomingMessageHandlerOG02 struct {
	Og  *Og
	Hub *Hub
}

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

type OGConfig struct {
	NetworkId   uint64
	GenesisPath string
}

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 NewOg

func NewOg(config OGConfig) (*Og, error)

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

func (*Og) GetHeight

func (og *Og) GetHeight() uint64

func (*Og) GetSequencerByHash

func (og *Og) GetSequencerByHash(hash types2.Hash) *types.Sequencer

func (*Og) Name

func (og *Og) Name() string

func (*Og) Start

func (og *Og) Start()

func (*Og) Stop

func (og *Og) Stop()

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 PeerProvider interface {
	BestPeerInfo() (peerId string, hash types.Hash, seqId uint64, err error)
	GetPeerHead(peerId string) (hash types.Hash, seqId uint64, err error)
}

type RequestCache

type RequestCache struct {
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL