@@ -344,51 +344,51 @@ Start is called when the stack is started
344
344
* TODO: start subservices like sword, swear, swarmdns
345
345
*/
346
346
// implements the node.Service interface
347
- func (self * Swarm ) Start (srv * p2p.Server ) error {
347
+ func (s * Swarm ) Start (srv * p2p.Server ) error {
348
348
startTime := time .Now ()
349
349
350
- self .tracerClose = tracing .Closer
350
+ s .tracerClose = tracing .Closer
351
351
352
352
// update uaddr to correct enode
353
- newaddr := self .bzz .UpdateLocalAddr ([]byte (srv .Self ().String ()))
353
+ newaddr := s .bzz .UpdateLocalAddr ([]byte (srv .Self ().String ()))
354
354
log .Info ("Updated bzz local addr" , "oaddr" , fmt .Sprintf ("%x" , newaddr .OAddr ), "uaddr" , fmt .Sprintf ("%s" , newaddr .UAddr ))
355
355
// set chequebook
356
356
//TODO: Currently if swap is enabled and no chequebook (or inexistent) contract is provided, the node would crash.
357
357
//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 != "" {
359
359
ctx := context .Background () // The initial setup has no deadline.
360
- err := self .SetChequebook (ctx )
360
+ err := s .SetChequebook (ctx )
361
361
if err != nil {
362
362
return fmt .Errorf ("Unable to set chequebook for SWAP: %v" , err )
363
363
}
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 ()))
365
365
} else {
366
366
log .Debug (fmt .Sprintf ("SWAP disabled: no cheque book set" ))
367
367
}
368
368
369
369
log .Info ("Starting bzz service" )
370
370
371
- err := self .bzz .Start (srv )
371
+ err := s .bzz .Start (srv )
372
372
if err != nil {
373
373
log .Error ("bzz failed" , "err" , err )
374
374
return err
375
375
}
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 ()))
377
377
378
- if self .ps != nil {
379
- self .ps .Start (srv )
378
+ if s .ps != nil {
379
+ s .ps .Start (srv )
380
380
}
381
381
382
382
// 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 )
386
386
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 )
389
389
}
390
390
391
- log .Debug ("Starting Swarm HTTP proxy" , "port" , self .config .Port )
391
+ log .Debug ("Starting Swarm HTTP proxy" , "port" , s .config .Port )
392
392
go func () {
393
393
err := server .ListenAndServe (addr )
394
394
if err != nil {
@@ -399,7 +399,7 @@ func (self *Swarm) Start(srv *p2p.Server) error {
399
399
400
400
doneC := make (chan struct {})
401
401
402
- self .cleanupFuncs = append (self .cleanupFuncs , func () error {
402
+ s .cleanupFuncs = append (s .cleanupFuncs , func () error {
403
403
close (doneC )
404
404
return nil
405
405
})
@@ -409,54 +409,54 @@ func (self *Swarm) Start(srv *p2p.Server) error {
409
409
select {
410
410
case <- time .After (updateGaugesPeriod ):
411
411
uptimeGauge .Update (time .Since (startTime ).Nanoseconds ())
412
- requestsCacheGauge .Update (int64 (self .netStore .RequestsCacheLen ()))
412
+ requestsCacheGauge .Update (int64 (s .netStore .RequestsCacheLen ()))
413
413
case <- doneC :
414
414
return
415
415
}
416
416
}
417
417
}(startTime )
418
418
419
419
startCounter .Inc (1 )
420
- self .streamer .Start (srv )
420
+ s .streamer .Start (srv )
421
421
return nil
422
422
}
423
423
424
424
// implements the node.Service interface
425
425
// 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 ()
429
429
if err != nil {
430
430
return err
431
431
}
432
432
}
433
433
434
- if self .ps != nil {
435
- self .ps .Stop ()
434
+ if s .ps != nil {
435
+ s .ps .Stop ()
436
436
}
437
- if ch := self .config .Swap .Chequebook (); ch != nil {
437
+ if ch := s .config .Swap .Chequebook (); ch != nil {
438
438
ch .Stop ()
439
439
ch .Save ()
440
440
}
441
- if self .swap != nil {
442
- self .swap .Close ()
441
+ if s .swap != nil {
442
+ s .swap .Close ()
443
443
}
444
- if self .accountingMetrics != nil {
445
- self .accountingMetrics .Close ()
444
+ if s .accountingMetrics != nil {
445
+ s .accountingMetrics .Close ()
446
446
}
447
- if self .netStore != nil {
448
- self .netStore .Close ()
447
+ if s .netStore != nil {
448
+ s .netStore .Close ()
449
449
}
450
- self .sfs .Stop ()
450
+ s .sfs .Stop ()
451
451
stopCounter .Inc (1 )
452
- self .streamer .Stop ()
452
+ s .streamer .Stop ()
453
453
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 ()
457
457
}
458
458
459
- for _ , cleanF := range self .cleanupFuncs {
459
+ for _ , cleanF := range s .cleanupFuncs {
460
460
err = cleanF ()
461
461
if err != nil {
462
462
log .Error ("encountered an error while running cleanup function" , "err" , err )
@@ -482,68 +482,73 @@ func (s *Swarm) Protocols() (protos []p2p.Protocol) {
482
482
483
483
// implements node.Service
484
484
// APIs returns the RPC API descriptors the Swarm implementation offers
485
- func (self * Swarm ) APIs () []rpc.API {
485
+ func (s * Swarm ) APIs () []rpc.API {
486
486
487
487
apis := []rpc.API {
488
488
// public APIs
489
489
{
490
490
Namespace : "bzz" ,
491
491
Version : "3.0" ,
492
- Service : & Info {self .config , chequebook .ContractParams },
492
+ Service : & Info {s .config , chequebook .ContractParams },
493
493
Public : true ,
494
494
},
495
495
// admin APIs
496
496
{
497
497
Namespace : "bzz" ,
498
498
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 ),
500
500
Public : false ,
501
501
},
502
502
{
503
503
Namespace : "chequebook" ,
504
504
Version : chequebook .Version ,
505
- Service : chequebook .NewAPI (self .config .Swap .Chequebook ),
505
+ Service : chequebook .NewAPI (s .config .Swap .Chequebook ),
506
506
Public : false ,
507
507
},
508
508
{
509
509
Namespace : "swarmfs" ,
510
510
Version : fuse .Swarmfs_Version ,
511
- Service : self .sfs ,
511
+ Service : s .sfs ,
512
512
Public : false ,
513
513
},
514
514
{
515
515
Namespace : "accounting" ,
516
516
Version : protocols .AccountingVersion ,
517
- Service : protocols .NewAccountingApi (self .accountingMetrics ),
517
+ Service : protocols .NewAccountingApi (s .accountingMetrics ),
518
518
Public : false ,
519
519
},
520
520
}
521
521
522
- apis = append (apis , self .bzz .APIs ()... )
522
+ apis = append (apis , s .bzz .APIs ()... )
523
523
524
- if self .ps != nil {
525
- apis = append (apis , self .ps .APIs ()... )
524
+ if s .ps != nil {
525
+ apis = append (apis , s .ps .APIs ()... )
526
526
}
527
527
528
528
return apis
529
529
}
530
530
531
531
// 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 )
534
534
if err != nil {
535
535
return err
536
536
}
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 ()))
538
538
return nil
539
539
}
540
540
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
+
541
546
// serialisable info about swarm
542
547
type Info struct {
543
548
* api.Config
544
549
* chequebook.Params
545
550
}
546
551
547
- func (self * Info ) Info () * Info {
548
- return self
552
+ func (s * Info ) Info () * Info {
553
+ return s
549
554
}
0 commit comments