@@ -344,51 +344,51 @@ Start is called when the stack is started
344344* TODO: start subservices like sword, swear, swarmdns
345345*/
346346// implements the node.Service interface
347- func (self * Swarm ) Start (srv * p2p.Server ) error {
347+ func (s * Swarm ) Start (srv * p2p.Server ) error {
348348 startTime := time .Now ()
349349
350- self .tracerClose = tracing .Closer
350+ s .tracerClose = tracing .Closer
351351
352352 // update uaddr to correct enode
353- newaddr := self .bzz .UpdateLocalAddr ([]byte (srv .Self ().String ()))
353+ newaddr := s .bzz .UpdateLocalAddr ([]byte (srv .Self ().String ()))
354354 log .Info ("Updated bzz local addr" , "oaddr" , fmt .Sprintf ("%x" , newaddr .OAddr ), "uaddr" , fmt .Sprintf ("%s" , newaddr .UAddr ))
355355 // set chequebook
356356 //TODO: Currently if swap is enabled and no chequebook (or inexistent) contract is provided, the node would crash.
357357 //Once we integrate back the contracts, this check MUST be revisited
358- if self .config .SwapEnabled && self .config .SwapAPI != "" {
358+ if s .config .SwapEnabled && s .config .SwapAPI != "" {
359359 ctx := context .Background () // The initial setup has no deadline.
360- err := self .SetChequebook (ctx )
360+ err := s .SetChequebook (ctx )
361361 if err != nil {
362362 return fmt .Errorf ("Unable to set chequebook for SWAP: %v" , err )
363363 }
364- log .Debug (fmt .Sprintf ("-> cheque book for SWAP: %v" , self .config .Swap .Chequebook ()))
364+ log .Debug (fmt .Sprintf ("-> cheque book for SWAP: %v" , s .config .Swap .Chequebook ()))
365365 } else {
366366 log .Debug (fmt .Sprintf ("SWAP disabled: no cheque book set" ))
367367 }
368368
369369 log .Info ("Starting bzz service" )
370370
371- err := self .bzz .Start (srv )
371+ err := s .bzz .Start (srv )
372372 if err != nil {
373373 log .Error ("bzz failed" , "err" , err )
374374 return err
375375 }
376- log .Info ("Swarm network started" , "bzzaddr" , fmt .Sprintf ("%x" , self .bzz .Hive .BaseAddr ()))
376+ log .Info ("Swarm network started" , "bzzaddr" , fmt .Sprintf ("%x" , s .bzz .Hive .BaseAddr ()))
377377
378- if self .ps != nil {
379- self .ps .Start (srv )
378+ if s .ps != nil {
379+ s .ps .Start (srv )
380380 }
381381
382382 // start swarm http proxy server
383- if self .config .Port != "" {
384- addr := net .JoinHostPort (self .config .ListenAddr , self .config .Port )
385- server := httpapi .NewServer (self .api , self .config .Cors )
383+ if s .config .Port != "" {
384+ addr := net .JoinHostPort (s .config .ListenAddr , s .config .Port )
385+ server := httpapi .NewServer (s .api , s .config .Cors )
386386
387- if self .config .Cors != "" {
388- log .Debug ("Swarm HTTP proxy CORS headers" , "allowedOrigins" , self .config .Cors )
387+ if s .config .Cors != "" {
388+ log .Debug ("Swarm HTTP proxy CORS headers" , "allowedOrigins" , s .config .Cors )
389389 }
390390
391- log .Debug ("Starting Swarm HTTP proxy" , "port" , self .config .Port )
391+ log .Debug ("Starting Swarm HTTP proxy" , "port" , s .config .Port )
392392 go func () {
393393 err := server .ListenAndServe (addr )
394394 if err != nil {
@@ -399,7 +399,7 @@ func (self *Swarm) Start(srv *p2p.Server) error {
399399
400400 doneC := make (chan struct {})
401401
402- self .cleanupFuncs = append (self .cleanupFuncs , func () error {
402+ s .cleanupFuncs = append (s .cleanupFuncs , func () error {
403403 close (doneC )
404404 return nil
405405 })
@@ -409,54 +409,54 @@ func (self *Swarm) Start(srv *p2p.Server) error {
409409 select {
410410 case <- time .After (updateGaugesPeriod ):
411411 uptimeGauge .Update (time .Since (startTime ).Nanoseconds ())
412- requestsCacheGauge .Update (int64 (self .netStore .RequestsCacheLen ()))
412+ requestsCacheGauge .Update (int64 (s .netStore .RequestsCacheLen ()))
413413 case <- doneC :
414414 return
415415 }
416416 }
417417 }(startTime )
418418
419419 startCounter .Inc (1 )
420- self .streamer .Start (srv )
420+ s .streamer .Start (srv )
421421 return nil
422422}
423423
424424// implements the node.Service interface
425425// stops all component services.
426- func (self * Swarm ) Stop () error {
427- if self .tracerClose != nil {
428- err := self .tracerClose .Close ()
426+ func (s * Swarm ) Stop () error {
427+ if s .tracerClose != nil {
428+ err := s .tracerClose .Close ()
429429 if err != nil {
430430 return err
431431 }
432432 }
433433
434- if self .ps != nil {
435- self .ps .Stop ()
434+ if s .ps != nil {
435+ s .ps .Stop ()
436436 }
437- if ch := self .config .Swap .Chequebook (); ch != nil {
437+ if ch := s .config .Swap .Chequebook (); ch != nil {
438438 ch .Stop ()
439439 ch .Save ()
440440 }
441- if self .swap != nil {
442- self .swap .Close ()
441+ if s .swap != nil {
442+ s .swap .Close ()
443443 }
444- if self .accountingMetrics != nil {
445- self .accountingMetrics .Close ()
444+ if s .accountingMetrics != nil {
445+ s .accountingMetrics .Close ()
446446 }
447- if self .netStore != nil {
448- self .netStore .Close ()
447+ if s .netStore != nil {
448+ s .netStore .Close ()
449449 }
450- self .sfs .Stop ()
450+ s .sfs .Stop ()
451451 stopCounter .Inc (1 )
452- self .streamer .Stop ()
452+ s .streamer .Stop ()
453453
454- err := self .bzz .Stop ()
455- if self .stateStore != nil {
456- self .stateStore .Close ()
454+ err := s .bzz .Stop ()
455+ if s .stateStore != nil {
456+ s .stateStore .Close ()
457457 }
458458
459- for _ , cleanF := range self .cleanupFuncs {
459+ for _ , cleanF := range s .cleanupFuncs {
460460 err = cleanF ()
461461 if err != nil {
462462 log .Error ("encountered an error while running cleanup function" , "err" , err )
@@ -482,68 +482,73 @@ func (s *Swarm) Protocols() (protos []p2p.Protocol) {
482482
483483// implements node.Service
484484// APIs returns the RPC API descriptors the Swarm implementation offers
485- func (self * Swarm ) APIs () []rpc.API {
485+ func (s * Swarm ) APIs () []rpc.API {
486486
487487 apis := []rpc.API {
488488 // public APIs
489489 {
490490 Namespace : "bzz" ,
491491 Version : "3.0" ,
492- Service : & Info {self .config , chequebook .ContractParams },
492+ Service : & Info {s .config , chequebook .ContractParams },
493493 Public : true ,
494494 },
495495 // admin APIs
496496 {
497497 Namespace : "bzz" ,
498498 Version : "3.0" ,
499- Service : api .NewInspector (self .api , self .bzz .Hive , self .netStore ),
499+ Service : api .NewInspector (s .api , s .bzz .Hive , s .netStore ),
500500 Public : false ,
501501 },
502502 {
503503 Namespace : "chequebook" ,
504504 Version : chequebook .Version ,
505- Service : chequebook .NewAPI (self .config .Swap .Chequebook ),
505+ Service : chequebook .NewAPI (s .config .Swap .Chequebook ),
506506 Public : false ,
507507 },
508508 {
509509 Namespace : "swarmfs" ,
510510 Version : fuse .Swarmfs_Version ,
511- Service : self .sfs ,
511+ Service : s .sfs ,
512512 Public : false ,
513513 },
514514 {
515515 Namespace : "accounting" ,
516516 Version : protocols .AccountingVersion ,
517- Service : protocols .NewAccountingApi (self .accountingMetrics ),
517+ Service : protocols .NewAccountingApi (s .accountingMetrics ),
518518 Public : false ,
519519 },
520520 }
521521
522- apis = append (apis , self .bzz .APIs ()... )
522+ apis = append (apis , s .bzz .APIs ()... )
523523
524- if self .ps != nil {
525- apis = append (apis , self .ps .APIs ()... )
524+ if s .ps != nil {
525+ apis = append (apis , s .ps .APIs ()... )
526526 }
527527
528528 return apis
529529}
530530
531531// SetChequebook ensures that the local checquebook is set up on chain.
532- func (self * Swarm ) SetChequebook (ctx context.Context ) error {
533- err := self .config .Swap .SetChequebook (ctx , self .backend , self .config .Path )
532+ func (s * Swarm ) SetChequebook (ctx context.Context ) error {
533+ err := s .config .Swap .SetChequebook (ctx , s .backend , s .config .Path )
534534 if err != nil {
535535 return err
536536 }
537- log .Info (fmt .Sprintf ("new chequebook set (%v): saving config file, resetting all connections in the hive" , self .config .Swap .Contract .Hex ()))
537+ log .Info (fmt .Sprintf ("new chequebook set (%v): saving config file, resetting all connections in the hive" , s .config .Swap .Contract .Hex ()))
538538 return nil
539539}
540540
541+ // RegisterPssProtocol adds a devp2p protocol to the swarm node's Pss instance
542+ func (s * Swarm ) RegisterPssProtocol (topic * pss.Topic , spec * protocols.Spec , targetprotocol * p2p.Protocol , options * pss.ProtocolParams ) (* pss.Protocol , error ) {
543+ return pss .RegisterProtocol (s .ps , topic , spec , targetprotocol , options )
544+ }
545+
541546// serialisable info about swarm
542547type Info struct {
543548 * api.Config
544549 * chequebook.Params
545550}
546551
547- func (self * Info ) Info () * Info {
548- return self
552+ func (s * Info ) Info () * Info {
553+ return s
549554}
0 commit comments