Skip to content

Commit

Permalink
added configurable refresh rate to boot
Browse files Browse the repository at this point in the history
  • Loading branch information
upperwal committed Aug 23, 2019
1 parent 7822288 commit d58537a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
8 changes: 5 additions & 3 deletions cmd/utils/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
mrand "math/rand"
"strconv"
"time"

logging "github.com/ipfs/go-log"
crypto "github.com/libp2p/go-libp2p-core/crypto"
Expand All @@ -16,8 +17,9 @@ import (
)

const (
BOOT_RNZ = "/BOOT_RNZ"
PORT = "4000"
BOOT_RNZ = "/BOOT_RNZ"
PORT = "4000"
REFRESH_RATE = 15 * time.Minute
)

var (
Expand Down Expand Up @@ -178,7 +180,7 @@ func boot(k crypto.PrivKey) {
return
}

bservice := bs.NewBootstrapService(false, BOOT_RNZ, cfg.BootstrapList)
bservice := bs.NewBootstrapService(false, BOOT_RNZ, cfg.BootstrapList, REFRESH_RATE)
app.InjectService(bservice)

err = app.Start()
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"crypto/ecdsa"
"crypto/x509"
"time"

logging "github.com/ipfs/go-log"
crypto "github.com/libp2p/go-libp2p-core/crypto"
Expand All @@ -20,8 +21,9 @@ type Config struct {
AccountCert *x509.Certificate

// Bootstrap
BootstrapNodes []string
BootstrapRendezvous string
BootstrapNodes []string
BootstrapRendezvous string
BootstrapRefreshRate time.Duration

// Remote Access
RemoteAccessURI string // TODO: what about the contract address?????
Expand Down
9 changes: 6 additions & 3 deletions config/const.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package config

import "time"

var (
BootstrapList = []string{
"/ip4/13.234.78.241/udp/4000/quic/p2p/QmVbcMycaK8ni5CeiM7JRjBRAdmwky6dQ6KcoxLesZDPk9",
}
remoteURI = ""
RpcURI = "127.0.0.1:"
RpcPort = 5555
remoteURI = ""
RpcURI = "127.0.0.1:"
RpcPort = 5555
BootstrapRefreshRate = 15 * time.Second
)
10 changes: 10 additions & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ var DefaultBootstrapRendezvous = func(cfg *Config) error {
return nil
}

// DefaultBootstrapRefreshRate specifies time interval to look for new peer nodes
var DefaultBootstrapRefreshRate = func(cfg *Config) error {
cfg.BootstrapRefreshRate = BootstrapRefreshRate
return nil
}

// DefaultRemoteAccessURI defines a remote point URL which is used for authentication of data topics, publishers and subscribers.
// It can be a central server or a blockchain service.
// It should support interface defined in 'interface/blockchain/blockchain.go'
Expand Down Expand Up @@ -87,6 +93,10 @@ var Defaults = []struct {
Fallback: func(cfg *Config) bool { return cfg.BootstrapRendezvous == "" },
Opt: DefaultBootstrapRendezvous,
},
{
Fallback: func(cfg *Config) bool { return cfg.BootstrapRefreshRate == 0 },
Opt: DefaultBootstrapRefreshRate,
},
{
Fallback: func(cfg *Config) bool { return cfg.RemoteAccessURI == "" },
Opt: DefaultRemoteAccessURI,
Expand Down
2 changes: 1 addition & 1 deletion mesh/mesh_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewMesh(ctx context.Context, opt ...config.Option) (*Mesh, error) {
return nil, err
}

bservice := bs.NewBootstrapService(false, cfg.BootstrapRendezvous, cfg.BootstrapNodes)
bservice := bs.NewBootstrapService(false, cfg.BootstrapRendezvous, cfg.BootstrapNodes, cfg.BootstrapRefreshRate)
app.InjectService(bservice)

f := fpubsub.NewFilter(ethDriver)
Expand Down
7 changes: 6 additions & 1 deletion service/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bootstrap

import (
"context"
"time"

logging "github.com/ipfs/go-log"
inet "github.com/libp2p/go-libp2p-core/network"
Expand Down Expand Up @@ -33,16 +34,20 @@ type BootstrapService struct {
ctxLocal context.Context
ctxLocalCancelFunc context.CancelFunc

// refresh rate
d time.Duration

s inet.Stream
}

// NewBootstrapService creates a new BootstrapService.
func NewBootstrapService(ann bool, rPoint string, bList []string) *BootstrapService {
func NewBootstrapService(ann bool, rPoint string, bList []string, d time.Duration) *BootstrapService {
hs := &BootstrapService{
announce: ann,
rendezvousPoint: rPoint,
bootstrapPeers: bList,
readyChanList: make([]chan interface{}, 0),
d: d,
}

hs.SetNameVersion(NAME, VERSION)
Expand Down
2 changes: 1 addition & 1 deletion service/bootstrap/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (bs *BootstrapService) announceAndFind() error {
discovery.Advertise(bs.ctxLocal, routingDiscovery, bs.rendezvousPoint)
log.Debug("Successfully announced!")

ticker := time.NewTicker(15 * time.Second)
ticker := time.NewTicker(bs.d)

for {
log.Debug("Searching for other peers...")
Expand Down

0 comments on commit d58537a

Please sign in to comment.