Documentation ¶
Overview ¶
simple abstraction for implementing pss functionality
the pss client library aims to simplify usage of the p2p.protocols package over pss
IO is performed using the ordinary p2p.MsgReadWriter interface, which transparently communicates with a pss node via RPC using websockets as transport layer, using methods in the PssAPI class in the swarm/pss package
Minimal-ish usage example (requires a running pss node with websocket RPC):
import ( "context" "fmt" "os" pss "github.com/insight-chain/inb-go/swarm/pss/client" "github.com/insight-chain/inb-go/p2p/protocols" "github.com/insight-chain/inb-go/p2p" "github.com/insight-chain/inb-go/swarm/pot" "github.com/insight-chain/inb-go/swarm/log" ) type FooMsg struct { Bar int } func fooHandler (msg interface{}) error { foomsg, ok := msg.(*FooMsg) if ok { log.Debug("Yay, just got a message", "msg", foomsg) } return errors.New(fmt.Sprintf("Unknown message")) } spec := &protocols.Spec{ Name: "foo", Version: 1, MaxMsgSize: 1024, Messages: []interface{}{ FooMsg{}, }, } proto := &p2p.Protocol{ Name: spec.Name, Version: spec.Version, Length: uint64(len(spec.Messages)), Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error { pp := protocols.NewPeer(p, rw, spec) return pp.Run(fooHandler) }, } func implementation() { cfg := pss.NewClientConfig() psc := pss.NewClient(context.Background(), nil, cfg) err := psc.Start() if err != nil { log.Crit("can't start pss client") os.Exit(1) } log.Debug("connected to pss node", "bzz addr", psc.BaseAddr) err = psc.RunProtocol(proto) if err != nil { log.Crit("can't start protocol on pss websocket") os.Exit(1) } addr := pot.RandomAddress() // should be a real address, of course psc.AddPssPeer(addr, spec) // use the protocol for something psc.Stop() }
BUG(test): TestIncoming test times out due to deadlock issues in the swarm hive
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { BaseAddrHex string // contains filtered or unexported fields }
The pss client provides devp2p emulation over pss RPC API, giving access to pss methods from a different process
func NewClientWithRPC ¶
Main constructor
The 'rpcclient' parameter allows passing a in-memory rpc client to act as the remote websocket RPC.
func (*Client) AddPssPeer ¶
Add a pss peer (public key) and run the protocol on it
client.RunProtocol with matching topic must have been run prior to adding the peer, or this method will return an error.
The key must exist in the key store of the pss node before the peer is added. The method will return an error if it is not.
func (*Client) RunProtocol ¶
Mounts a new devp2p protcool on the pss connection
the protocol is aliased as a "pss topic" uses normal devp2p send and incoming message handler routines from the p2p/protocols package
when an incoming message is received from a peer that is not yet known to the client, this peer object is instantiated, and the protocol is run on it.
Notes ¶
Bugs ¶
TestIncoming test times out due to deadlock issues in the swarm hive