api

package
v0.0.0-...-4ca2c20 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusMsg              = 0x00
	P2PMessageEventMsg     = 0x01
	ChannelMessageEventMsg = 0x02
)

uint64 MsgCode

View Source
const ProtocolName = "p2pchat"
View Source
const ProtocolVersion = 1

Variables

View Source
var DefaultBackendConfig = BackendConfig{
	MaxPeers: 50,
	Locally:  true,
	NAT:      nat.Any(),
	Address:  "127.0.0.1:0",
}

Functions

func Handle

func Handle(backend *Backend, peer *p2p.Peer, rw p2p.MsgReadWriter) error

Handle received message, exit with any protocol-level errors

func MakeProtocols

func MakeProtocols(backend *Backend) []p2p.Protocol

MakeProtocols always returns latest protocol and drop support for old protocol version.

func SendJson

func SendJson(w p2p.MsgWriter, msgcode uint64, data interface{}) error

Types

type Backend

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

Backend defines events trigger

func NewBackend

func NewBackend(config BackendConfig) *Backend

func (*Backend) Decrypt

func (b *Backend) Decrypt(pubkey *ecdsa.PublicKey, ciphertext []byte) ([]byte, error)

func (*Backend) Encrypt

func (b *Backend) Encrypt(pubkey *ecdsa.PublicKey, plaintext []byte) ([]byte, error)

func (*Backend) PeersInfo

func (b *Backend) PeersInfo() *[]peersInfo

func (*Backend) SelfID

func (b *Backend) SelfID() enode.ID

func (*Backend) SendP2PMessage

func (b *Backend) SendP2PMessage(nodeID [32]byte, message types.Message) error

func (*Backend) SessionID

func (b *Backend) SessionID(nodeID [32]byte) [32]byte

SessionID returns p2p session ID for database, empty bytes if nodeID equals to self ID

func (*Backend) Start

func (b *Backend) Start()

Start p2p server and backend in goroutine

func (*Backend) Stop

func (b *Backend) Stop()

func (*Backend) Verify

func (b *Backend) Verify(pubkey *ecdsa.PublicKey, gatewaySelf, gatewayTarget string) ([]string, error)

type BackendConfig

type BackendConfig struct {
	Key      *ecdsa.PrivateKey
	MaxPeers int           // default to 50
	NAT      nat.Interface // p2p.nat.Parse
	Address  string        // default to "127.0.0.1:0"
	Locally  bool          // restrict local request

	BootstrapNodes []*enode.Node // enode.MustParse

	// for test
	NetRestrict *netutil.Netlist // p2p.netutil.ParseNetlist
}

type Peer

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

func NewPeer

func NewPeer(p *p2p.Peer, rw p2p.MsgReadWriter, version uint) *Peer

func (*Peer) Close

func (p *Peer) Close()

func (*Peer) SendMessage

func (p *Peer) SendMessage(event types.P2PMessageEvent) error

Jump to

Keyboard shortcuts

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