diff --git a/conf/config.go b/conf/config.go index c90a5a9..894b933 100644 --- a/conf/config.go +++ b/conf/config.go @@ -9,6 +9,8 @@ type Config struct { PublicKeyPath string PrivateKeyPath string DHTEndpointPort int64 + + BootstrapAddress string } var instance *Config diff --git a/infrastructure/dht.go b/infrastructure/dht.go index e73d847..0931714 100644 --- a/infrastructure/dht.go +++ b/infrastructure/dht.go @@ -20,6 +20,7 @@ import ( dht "github.com/libp2p/go-libp2p-kad-dht" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peer" ) type DHTRecord struct { @@ -78,6 +79,17 @@ func Init(ctx context.Context) (*DHTService, error) { if err != nil { return nil, err } + pi, err := peer.AddrInfoFromString(conf.GetConfig().BootstrapAddress) + if err != nil { + return nil, err + } + logger := oclib.GetLogger() + if err := h.Connect(ctx, *pi); err != nil { + logger.Err(fmt.Errorf("Failed to connect to MAIN bootstrap peer %s: %s", pi.ID, err)) + } else { + logger.Info().Msg(fmt.Sprintf("Connected to MAIN bootstrap peer %s", pi.ID)) + } + singletonService = service if VerifyPubWithPriv() { if _, err := singletonService.ClaimName(context.Background(), diff --git a/main.go b/main.go index 8918d60..672a4cb 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,8 @@ func main() { conf.GetConfig().PublicKeyPath = o.GetStringDefault("PEER_PUBLIC_KEY_PATH", "./pem/public.pem") conf.GetConfig().PrivateKeyPath = o.GetStringDefault("PEER_PRIVATE_KEY_PATH", "./pem/private.pem") conf.GetConfig().DHTEndpointPort = o.GetInt64Default("DHT_ENDPOINT_PORT", 4001) + + conf.GetConfig().BootstrapAddress = o.GetStringDefault("BOOTSTRAP_ADDRESS", "") // Beego init beego.BConfig.AppName = appname beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080)