network

package
v0.0.0-...-77960fc Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: GPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
	DefaultHTTPPort = 8545        // Default TCP port for the HTTP RPC server
	DefaultWSHost   = "localhost" // Default host interface for the websocket RPC server
	DefaultWSPort   = 8546        // Default TCP port for the websocket RPC server
)

Variables

View Source
var DefaultConfig = Config{
	DataDir:          DefaultDataDir(),
	HTTPPort:         DefaultHTTPPort,
	HTTPModules:      []string{"net", "web3"},
	HTTPVirtualHosts: []string{"localhost"},
	WSPort:           DefaultWSPort,
	WSModules:        []string{"net", "web3"},
	P2P: p2p.Config{
		ListenAddr: ":30303",
		MaxPeers:   25,
		NAT:        nat.Any(),
	},
}

DefaultConfig contains reasonable default settings.

Functions

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir is the default data directory to use for the databases and other persistence requirements.

func DefaultHTTPEndpoint

func DefaultHTTPEndpoint() string

DefaultHTTPEndpoint returns the HTTP endpoint used by default.

func DefaultIPCEndpoint

func DefaultIPCEndpoint(clientIdentifier string) string

DefaultIPCEndpoint returns the IPC path used by default.

func DefaultWSEndpoint

func DefaultWSEndpoint() string

DefaultWSEndpoint returns the websocket endpoint used by default.

func Fake

func Fake()

Types

type Client

type Client struct {
}

Client sends out connection

type Config

type Config struct {
	// Name sets the instance name of the node. It must not contain the / character and is
	// used in the devp2p node identifier. The instance name of geth is "geth". If no
	// value is specified, the basename of the current executable is used.
	Name string `toml:"-"`

	// UserIdent, if set, is used as an additional component in the devp2p node identifier.
	UserIdent string `toml:",omitempty"`

	// Version should be set to the version number of the program. It is used
	// in the devp2p node identifier.
	Version string `toml:"-"`

	// DataDir is the file system folder the node should use for any data storage
	// requirements. The configured data directory will not be directly shared with
	// registered services, instead those can use utility methods to create/access
	// databases or flat files. This enables ephemeral nodes which can fully reside
	// in memory.
	DataDir string

	// Configuration of peer-to-peer networking.
	P2P p2p.Config

	// KeyStoreDir is the file system folder that contains private keys. The directory can
	// be specified as a relative path, in which case it is resolved relative to the
	// current directory.
	//
	// If KeyStoreDir is empty, the default location is the "keystore" subdirectory of
	// DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory
	// is created by New and destroyed when the node is stopped.
	KeyStoreDir string `toml:",omitempty"`

	// UseLightweightKDF lowers the memory and CPU requirements of the key store
	// scrypt KDF at the expense of security.
	UseLightweightKDF bool `toml:",omitempty"`

	// NoUSB disables hardware wallet monitoring and connectivity.
	NoUSB bool `toml:",omitempty"`

	// IPCPath is the requested location to place the IPC endpoint. If the path is
	// a simple file name, it is placed inside the data directory (or on the root
	// pipe path on Windows), whereas if it's a resolvable path name (absolute or
	// relative), then that specific path is enforced. An empty path disables IPC.
	IPCPath string `toml:",omitempty"`

	// HTTPHost is the host interface on which to start the HTTP RPC server. If this
	// field is empty, no HTTP API endpoint will be started.
	HTTPHost string `toml:",omitempty"`

	// HTTPPort is the TCP port number on which to start the HTTP RPC server. The
	// default zero value is/ valid and will pick a port number randomly (useful
	// for ephemeral nodes).
	HTTPPort int `toml:",omitempty"`

	// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
	// clients. Please be aware that CORS is a browser enforced security, it's fully
	// useless for custom HTTP clients.
	HTTPCors []string `toml:",omitempty"`

	// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
	// This is by default {'localhost'}. Using this prevents attacks like
	// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
	// origin. These attacks do not utilize CORS, since they are not cross-domain.
	// By explicitly checking the Host-header, the server will not allow requests
	// made against the server with a malicious host domain.
	// Requests using ip address directly are not affected
	HTTPVirtualHosts []string `toml:",omitempty"`

	// HTTPModules is a list of API modules to expose via the HTTP RPC interface.
	// If the module list is empty, all RPC API endpoints designated public will be
	// exposed.
	HTTPModules []string `toml:",omitempty"`

	// WSHost is the host interface on which to start the websocket RPC server. If
	// this field is empty, no websocket API endpoint will be started.
	WSHost string `toml:",omitempty"`

	// WSPort is the TCP port number on which to start the websocket RPC server. The
	// default zero value is/ valid and will pick a port number randomly (useful for
	// ephemeral nodes).
	WSPort int `toml:",omitempty"`

	// WSOrigins is the list of domain to accept websocket requests from. Please be
	// aware that the server can only act upon the HTTP request the client sends and
	// cannot verify the validity of the request header.
	WSOrigins []string `toml:",omitempty"`

	// WSModules is a list of API modules to expose via the websocket RPC interface.
	// If the module list is empty, all RPC API endpoints designated public will be
	// exposed.
	WSModules []string `toml:",omitempty"`

	// WSExposeAll exposes all API modules via the WebSocket RPC interface rather
	// than just the public ones.
	//
	// *WARNING* Only set this if the node is running in a trusted network, exposing
	// private APIs to untrusted users is a major security risk.
	WSExposeAll bool `toml:",omitempty"`

	// Logger is a custom logger to use with the p2p.Server.
	Logger log.Logger `toml:",omitempty"`
}

Config represents a small collection of configuration values to fine tune the P2P network layer of a protocol stack. These values can be further extended by all registered services.

func (*Config) AccountConfig

func (c *Config) AccountConfig() (int, int, string, error)

AccountConfig determines the settings for scrypt and keydirectory

func (*Config) HTTPEndpoint

func (c *Config) HTTPEndpoint() string

HTTPEndpoint resolves an HTTP endpoint based on the configured host interface and port parameters.

func (*Config) IPCEndpoint

func (c *Config) IPCEndpoint() string

IPCEndpoint resolves an IPC endpoint based on a configured value, taking into account the set data folders as well as the designated platform we're currently running on.

func (*Config) NodeDB

func (c *Config) NodeDB() string

NodeDB returns the path to the discovery node database.

func (*Config) NodeKey

func (c *Config) NodeKey() *ecdsa.PrivateKey

NodeKey retrieves the currently configured private key of the node, checking first any manually set key, falling back to the one found in the configured data folder. If no key can be found, a new one is generated.

func (*Config) NodeName

func (c *Config) NodeName() string

NodeName returns the devp2p node identifier.

func (*Config) StaticNodes

func (c *Config) StaticNodes() []*discover.Node

StaticNodes returns a list of node enode URLs configured as static nodes.

func (*Config) TrustedNodes

func (c *Config) TrustedNodes() []*discover.Node

TrustedNodes returns a list of node enode URLs configured as trusted nodes.

func (*Config) WSEndpoint

func (c *Config) WSEndpoint() string

WSEndpoint resolves a websocket endpoint based on the configured host interface and port parameters.

type CxData

type CxData struct {
	Abi interface{} `json:"abi"`
	Bin string      `json:"bytecode"`
}

type HTTPServer

type HTTPServer struct {
	Port   int
	Plasma *plasma.Plasma
	Chain  *core.BlockChain
	// contains filtered or unexported fields
}

HTTPServer serves HTTP requests

func (*HTTPServer) Shutdown

func (hs *HTTPServer) Shutdown(ctx context.Context)

Shutdown stops http processing

func (*HTTPServer) Start

func (hs *HTTPServer) Start() error

Start is called to accept http requests

type Node

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

Node is a P2P network member, it can acts both as client and server

func (*Node) Start

func (n *Node) Start() (err error)

Start the node

type P2PLocalHost

type P2PLocalHost struct {
	Port int
	// Plasma *plasma.Plasma
	// Chain  *core.BlockChain
	host.Host
	RemotePeerCaches map[ipeer.ID]*RemotePeerCache
}

LocalHost serves P2P requests

func (P2PLocalHost) Decode

func (localhost P2PLocalHost) Decode(data []byte, out interface{}) error

func (P2PLocalHost) MarkBlock

func (localhost P2PLocalHost) MarkBlock(peerid ipeer.ID, block *types.Block)

func (P2PLocalHost) MarkTxs

func (localhost P2PLocalHost) MarkTxs(peerid ipeer.ID, txs types.Transactions)

func (P2PLocalHost) PeerIDs

func (localhost P2PLocalHost) PeerIDs() []ipeer.ID

func (P2PLocalHost) PeerIDsWithoutBlock

func (localhost P2PLocalHost) PeerIDsWithoutBlock(hash common.Hash) []ipeer.ID

func (P2PLocalHost) PeerIDsWithoutTx

func (localhost P2PLocalHost) PeerIDsWithoutTx(hash common.Hash) []ipeer.ID

func (P2PLocalHost) Request

func (localhost P2PLocalHost) Request(proto string, peerid ipeer.ID, data interface{}) ([]byte, error)

func (P2PLocalHost) Response

func (localhost P2PLocalHost) Response(s inet.Stream, data interface{}) error

func (P2PLocalHost) SendMsg

func (localhost P2PLocalHost) SendMsg(proto string, peerid ipeer.ID, data interface{}) error

type RPCConfig

type RPCConfig struct {
	Proto   string // network: tcp, udp, unix domain ...
	Port    int
	Methods map[string]interface{}
}

RPCConfig holds the configuraiton for rpc service

type RPCServer

type RPCServer struct {
	RPCConfig
	// contains filtered or unexported fields
}

RPCServer handle incoming connections

func ServeRPC

func ServeRPC(c RPCConfig) (*RPCServer, error)

ServeRPC on a port and return the RPCServer instance listening

type RPCService

type RPCService struct {
}

type RemotePeerCache

type RemotePeerCache struct {
	KnownTxs   set.Interface
	KnownBlock set.Interface
	// contains filtered or unexported fields
}

RemotePeerCache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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