server

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 41 Imported by: 8

Documentation

Index

Constants

View Source
const (
	BanReasonNodeMisbehaving int = 1
	BanReasonManuallyAdded   int = 2

	// REVERT_TO_INV_DIFF when peer is neer to tip, set its revertToInv to false back
	REVERT_TO_INV_DIFF = 7
)

Variables

This section is empty.

Functions

func ProcessForRPC

func ProcessForRPC(message interface{}) (rsp interface{}, err error)

ProcessForRPC are RPC process things

func SetMsgHandle

func SetMsgHandle(ctx context.Context, msgChan <-chan *peer.PeerMessage, server *Server)

SetMsgHandle create a msgHandle for these message from peer And RPC. Then begins the core block handler which processes block and inv messages.

Types

type BannedInfo added in v0.0.4

type BannedInfo struct {
	Address    string
	BanUntil   int64
	CreateTime int64
	Reason     int
}

type MsgHandle

type MsgHandle struct {
	*Server
	// contains filtered or unexported fields
}

type PingMsg added in v0.0.7

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

type RPCConnManager

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

RPCConnManager provides a connection manager for use with the RPC server and implements the rpcserverConnManager interface.

func NewRPCConnManager

func NewRPCConnManager(s *Server) *RPCConnManager

func (*RPCConnManager) AddRebroadcastInventory

func (cm *RPCConnManager) AddRebroadcastInventory(iv *wire.InvVect, data interface{})

AddRebroadcastInventory adds the provided inventory to the list of inventories to be rebroadcast at random intervals until they show up in a block.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) BroadcastMessage

func (cm *RPCConnManager) BroadcastMessage(msg wire.Message)

BroadcastMessage sends the provided message to all currently connected peers.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) ClearBanned added in v0.0.4

func (cm *RPCConnManager) ClearBanned()

func (*RPCConnManager) Connect

func (cm *RPCConnManager) Connect(addr string, permanent bool) error

Connect adds the provided address as a new outbound peer. The permanent flag indicates whether or not to make the peer persistent and reconnect if the connection is lost. Attempting to connect to an already existing peer will return an error.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) ConnectedCount

func (cm *RPCConnManager) ConnectedCount() int32

ConnectedCount returns the number of currently connected peers.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) ConnectedPeers

func (cm *RPCConnManager) ConnectedPeers() []RPCServerPeer

ConnectedPeers returns an array consisting of all connected peers.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) DisconnectByAddr

func (cm *RPCConnManager) DisconnectByAddr(addr string) error

DisconnectByAddr disconnects the peer associated with the provided address. This applies to both inbound and outbound peers. Attempting to remove an address that does not exist will return an error.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) DisconnectByID

func (cm *RPCConnManager) DisconnectByID(id int32) error

DisconnectByID disconnects the peer associated with the provided id. This applies to both inbound and outbound peers. Attempting to remove an id that does not exist will return an error.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) ListBanned added in v0.0.4

func (cm *RPCConnManager) ListBanned() (*btcjson.ListBannedResult, *btcjson.RPCError)

func (*RPCConnManager) NetTotals

func (cm *RPCConnManager) NetTotals() (uint64, uint64)

NetTotals returns the sum of all bytes received and sent across the network for all peers.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) PersistentPeers

func (cm *RPCConnManager) PersistentPeers() []RPCServerPeer

PersistentPeers returns an array consisting of all the added persistent peers.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) RemoveByAddr

func (cm *RPCConnManager) RemoveByAddr(addr string) error

RemoveByAddr removes the peer associated with the provided address from the list of persistent peers. Attempting to remove an address that does not exist will return an error.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) RemoveByID

func (cm *RPCConnManager) RemoveByID(id int32) error

RemoveByID removes the peer associated with the provided id from the list of persistent peers. Attempting to remove an id that does not exist will return an error.

This function is safe for concurrent access and is part of the rpcserverConnManager interface implementation.

func (*RPCConnManager) SetBan added in v0.0.4

type RPCServerPeer

type RPCServerPeer interface {
	// ToPeer returns the underlying peer instance.
	ToPeer() *peer.Peer

	// IsTxRelayDisabled returns whether or not the peer has disabled
	// transaction relay.
	IsTxRelayDisabled() bool

	// BanScore returns the current integer value that represents how close
	// the peer is to being banned.
	BanScore() uint32

	// FeeFilter returns the requested current minimum fee rate for which
	// transactions should be announced.
	FeeFilter() int64
}

RPCServerPeer represents a peer for use with the RPC server.

The interface contract requires that all of these methods are safe for concurrent access.

type Server

type Server struct {
	MsgChan chan *peer.PeerMessage
	// contains filtered or unexported fields
}

Server provides a bitcoin server for handling communications to and from bitcoin peers.

func NewServer

func NewServer(chainParams *model.BitcoinParams, ts *util.MedianTime, interrupt <-chan struct{}) (*Server, error)

func (*Server) AddBanScore added in v0.0.4

func (s *Server) AddBanScore(peerAddr string, persistent uint32, transient uint32, reason string)

func (*Server) AddBytesReceived

func (s *Server) AddBytesReceived(bytesReceived uint64)

AddBytesReceived adds the passed number of bytes to the total bytes received counter for the server. It is safe for concurrent access.

func (*Server) AddBytesSent

func (s *Server) AddBytesSent(bytesSent uint64)

AddBytesSent adds the passed number of bytes to the total bytes sent counter for the server. It is safe for concurrent access.

func (*Server) AddPeer

func (s *Server) AddPeer(sp *serverPeer)

AddPeer adds a new peer that has already been connected to the server.

func (*Server) AddRebroadcastInventory

func (s *Server) AddRebroadcastInventory(iv *wire.InvVect, data interface{})

AddRebroadcastInventory adds 'iv' to the list of inventories to be rebroadcasted at random intervals until they show up in a block.

func (*Server) AnnounceNewTransactions

func (s *Server) AnnounceNewTransactions(txns []*mempool.TxEntry)

AnnounceNewTransactions generates and relays inventory vectors and notifies both websocket and getblocktemplate long poll clients of the passed transactions. This function should be called whenever new transactions are added to the mempool.

func (*Server) BanAddr added in v0.0.4

func (s *Server) BanAddr(addr string, startTime int64, endTime int64, reason int) bool

func (*Server) BanPeer

func (s *Server) BanPeer(sp *serverPeer)

BanPeer bans a peer that has already been connected to the server by ip.

func (*Server) BroadcastMessage

func (s *Server) BroadcastMessage(msg wire.Message, exclPeers ...*serverPeer)

BroadcastMessage sends msg to all peers currently connected to the server except those in the passed peers to exclude.

func (*Server) ClearBanned added in v0.0.4

func (s *Server) ClearBanned()

func (*Server) ConnectedCount

func (s *Server) ConnectedCount() int32

ConnectedCount returns the number of currently connected peers.

func (*Server) GetBannedInfo added in v0.0.4

func (s *Server) GetBannedInfo() []*BannedInfo

func (*Server) HandleMinedBlock added in v0.0.3

func (s *Server) HandleMinedBlock(pblock *block.Block, done chan error)

func (*Server) NetTotals

func (s *Server) NetTotals() (uint64, uint64)

NetTotals returns the sum of all bytes received and sent across the network for all peers. It is safe for concurrent access.

func (*Server) OutboundGroupCount

func (s *Server) OutboundGroupCount(key string) int

OutboundGroupCount returns the number of peers connected to the given outbound group key.

func (*Server) RelayBlocks added in v0.0.7

func (s *Server) RelayBlocks(invVects []*wire.InvVect, headers []*block.BlockHeader)

func (*Server) RelayInventory

func (s *Server) RelayInventory(invVect *wire.InvVect, data interface{})

RelayInventory relays the passed inventory vector to all connected peers that are not already known to have it.

func (*Server) RelayUpdatedTipBlocks

func (s *Server) RelayUpdatedTipBlocks(event *chain.TipUpdatedEvent)

RelayUpdatedTipBlocks relays blocks leads to new main chain

func (*Server) RemoveRebroadcastInventory

func (s *Server) RemoveRebroadcastInventory(iv *wire.InvVect)

RemoveRebroadcastInventory removes 'iv' from the list of items to be rebroadcasted if present.

func (*Server) ScheduleShutdown

func (s *Server) ScheduleShutdown(duration time.Duration)

ScheduleShutdown schedules a server shutdown after the specified duration. It also dynamically adjusts how often to warn the server is going down based on remaining duration.

func (*Server) Start

func (s *Server) Start()

Start begins accepting connections from peers.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the server by stopping and disconnecting all peers and the main listener.

func (*Server) TransactionConfirmed

func (s *Server) TransactionConfirmed(tx *tx.Tx)

TransactionConfirmed marks a Transaction as no longer needing rebroadcasting when it has one confirmation on the main chain.

func (*Server) UnbanAddr added in v0.0.4

func (s *Server) UnbanAddr(addr string) bool

func (*Server) UpdatePeerHeights

func (s *Server) UpdatePeerHeights(latestBlkHash *util.Hash, latestHeight int32, updateSource *peer.Peer)

UpdatePeerHeights updates the heights of all peers who have have announced the latest connected main chain block, or a recognized orphan. These height updates allow us to dynamically refresh peer heights, ensuring sync peer selection has access to the latest block heights for each peer.

func (*Server) WaitForShutdown

func (s *Server) WaitForShutdown()

WaitForShutdown blocks until the main listener and peer handlers are stopped.

type TxRelayer added in v0.0.7

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

func NewTxRelayer added in v0.0.7

func NewTxRelayer() *TxRelayer

func (*TxRelayer) Cache added in v0.0.7

func (txr *TxRelayer) Cache(txID *util.Hash, txn *tx.Tx)

func (*TxRelayer) TxToRelay added in v0.0.7

func (txr *TxRelayer) TxToRelay(txID *util.Hash) *tx.Tx

Jump to

Keyboard shortcuts

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