swarm: Reinstate Pss Protocol add call through swarm service

This commit is contained in:
lash 2019-02-18 10:06:20 +01:00
parent c0b9c763bb
commit 4d1810a1a4

View file

@ -482,68 +482,73 @@ func (s *Swarm) Protocols() (protos []p2p.Protocol) {
// implements node.Service // implements node.Service
// APIs returns the RPC API descriptors the Swarm implementation offers // APIs returns the RPC API descriptors the Swarm implementation offers
func (self *Swarm) APIs() []rpc.API { func (s *Swarm) APIs() []rpc.API {
apis := []rpc.API{ apis := []rpc.API{
// public APIs // public APIs
{ {
Namespace: "bzz", Namespace: "bzz",
Version: "3.0", Version: "3.0",
Service: &Info{self.config, chequebook.ContractParams}, Service: &Info{s.config, chequebook.ContractParams},
Public: true, Public: true,
}, },
// admin APIs // admin APIs
{ {
Namespace: "bzz", Namespace: "bzz",
Version: "3.0", Version: "3.0",
Service: api.NewInspector(self.api, self.bzz.Hive, self.netStore), Service: api.NewInspector(s.api, s.bzz.Hive, s.netStore),
Public: false, Public: false,
}, },
{ {
Namespace: "chequebook", Namespace: "chequebook",
Version: chequebook.Version, Version: chequebook.Version,
Service: chequebook.NewAPI(self.config.Swap.Chequebook), Service: chequebook.NewAPI(s.config.Swap.Chequebook),
Public: false, Public: false,
}, },
{ {
Namespace: "swarmfs", Namespace: "swarmfs",
Version: fuse.Swarmfs_Version, Version: fuse.Swarmfs_Version,
Service: self.sfs, Service: s.sfs,
Public: false, Public: false,
}, },
{ {
Namespace: "accounting", Namespace: "accounting",
Version: protocols.AccountingVersion, Version: protocols.AccountingVersion,
Service: protocols.NewAccountingApi(self.accountingMetrics), Service: protocols.NewAccountingApi(s.accountingMetrics),
Public: false, Public: false,
}, },
} }
apis = append(apis, self.bzz.APIs()...) apis = append(apis, s.bzz.APIs()...)
if self.ps != nil { if s.ps != nil {
apis = append(apis, self.ps.APIs()...) apis = append(apis, s.ps.APIs()...)
} }
return apis return apis
} }
// SetChequebook ensures that the local checquebook is set up on chain. // SetChequebook ensures that the local checquebook is set up on chain.
func (self *Swarm) SetChequebook(ctx context.Context) error { func (s *Swarm) SetChequebook(ctx context.Context) error {
err := self.config.Swap.SetChequebook(ctx, self.backend, self.config.Path) err := s.config.Swap.SetChequebook(ctx, s.backend, s.config.Path)
if err != nil { if err != nil {
return err return err
} }
log.Info(fmt.Sprintf("new chequebook set (%v): saving config file, resetting all connections in the hive", self.config.Swap.Contract.Hex())) log.Info(fmt.Sprintf("new chequebook set (%v): saving config file, resetting all connections in the hive", s.config.Swap.Contract.Hex()))
return nil return nil
} }
// RegisterPssProtocol adds a devp2p protocol to the swarm node's Pss instance
func (s *Swarm) RegisterPssProtocol(topic *pss.Topic, spec *protocols.Spec, targetprotocol *p2p.Protocol, options *pss.ProtocolParams) (*pss.Protocol, error) {
return pss.RegisterProtocol(s.ps, topic, spec, targetprotocol, options)
}
// serialisable info about swarm // serialisable info about swarm
type Info struct { type Info struct {
*api.Config *api.Config
*chequebook.Params *chequebook.Params
} }
func (self *Info) Info() *Info { func (s *Info) Info() *Info {
return self return s
} }