diff --git a/impl/internal/dht/get.go b/impl/internal/dht/get.go index 5f973102..10ac68b1 100644 --- a/impl/internal/dht/get.go +++ b/impl/internal/dht/get.go @@ -47,17 +47,19 @@ func startGetTraversal( if sha1.Sum(bv) == target { select { case vChan <- FullGetResult{ - V: rv, - Sig: r.Sig, + V: rv, + Sig: r.Sig, + Mutable: false, }: case <-ctx.Done(): } } else if sha1.Sum(append(r.K[:], salt...)) == target && bep44.Verify(r.K[:], salt, *r.Seq, bv, r.Sig[:]) { select { case vChan <- FullGetResult{ - Seq: *r.Seq, - V: rv, - Sig: r.Sig, + Seq: *r.Seq, + V: rv, + Sig: r.Sig, + Mutable: true, }: case <-ctx.Done(): } diff --git a/impl/internal/did/client.go b/impl/internal/did/client.go index 84ac209d..d945e21b 100644 --- a/impl/internal/did/client.go +++ b/impl/internal/did/client.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "net/url" + "time" "github.com/TBD54566975/ssi-sdk/did" "github.com/anacrolix/dht/v2/bep44" @@ -24,9 +25,11 @@ func NewGatewayClient(gatewayURL string) (*GatewayClient, error) { if _, err := url.Parse(gatewayURL); err != nil { return nil, err } + client := http.DefaultClient + client.Timeout = time.Second * 10 return &GatewayClient{ gatewayURL: gatewayURL, - client: http.DefaultClient, + client: client, }, nil } diff --git a/impl/internal/did/client_test.go b/impl/internal/did/client_test.go index 42ceecd3..957b7fa1 100644 --- a/impl/internal/did/client_test.go +++ b/impl/internal/did/client_test.go @@ -42,6 +42,17 @@ func TestClient(t *testing.T) { t.Logf("time to put and get: %s", since) } +func TestGet(t *testing.T) { + client, err := NewGatewayClient("http://localhost:8305") + + require.NoError(t, err) + require.NotNil(t, client) + + doc, _, _, err := client.GetDIDDocument("did:dht:uqaj3fcr9db6jg6o9pjs53iuftyj45r46aubogfaceqjbo6pp9sy") + require.NoError(t, err) + require.NotNil(t, doc) +} + func TestClientInvalidGateway(t *testing.T) { g, err := NewGatewayClient("\n") assert.Error(t, err) diff --git a/impl/pkg/dht/dht.go b/impl/pkg/dht/dht.go index d48e147f..0a580606 100644 --- a/impl/pkg/dht/dht.go +++ b/impl/pkg/dht/dht.go @@ -33,7 +33,6 @@ func NewDHT(bootstrapPeers []string) (*DHT, error) { logrus.WithField("bootstrap_peers", len(bootstrapPeers)).Info("initializing DHT") c := dht.NewDefaultServerConfig() - // change default expire to 24 hours c.Exp = time.Hour * 24 c.NoSecurity = false conn, err := net.ListenPacket("udp", "0.0.0.0:6881") @@ -134,7 +133,7 @@ func (d *DHT) GetFull(ctx context.Context, key string) (*dhtint.FullGetResult, e z32Decoded, err := util.Z32Decode(key) if err != nil { - return nil, errutil.LoggingCtxErrorMsgf(ctx, err, "failed to decode key [%s]", key) + return nil, errors.Wrapf(err, "failed to decode key [%s]", key) } res, t, err := dhtint.Get(ctx, infohash.HashBytes(z32Decoded), d.Server, nil, nil) if err != nil { diff --git a/impl/pkg/dht/logging.go b/impl/pkg/dht/logging.go index 58083179..f54fb3c1 100644 --- a/impl/pkg/dht/logging.go +++ b/impl/pkg/dht/logging.go @@ -6,6 +6,7 @@ import ( ) func init() { + logrus.SetFormatter(&logrus.JSONFormatter{}) log.Default.Handlers = []log.Handler{logrusHandler{}} } @@ -19,12 +20,12 @@ func (logrusHandler) Handle(record log.Record) { switch record.Level { case log.Debug: - entry.Debug(msg) + entry.Debugf("%s\n", msg) case log.Info: - entry.Info(msg) + entry.Infof("%s\n", msg) case log.Warning, log.Error: - entry.Warn(msg) + entry.Warnf("%s\n", msg) default: - entry.Debug(msg) + entry.Debugf("%s\n", msg) } } diff --git a/impl/pkg/server/server.go b/impl/pkg/server/server.go index 97b7852c..66bb7138 100644 --- a/impl/pkg/server/server.go +++ b/impl/pkg/server/server.go @@ -70,9 +70,9 @@ func NewServer(cfg *config.Config, shutdown chan os.Signal, d *dht.DHT) (*Server Server: &http.Server{ Addr: fmt.Sprintf("%s:%d", cfg.ServerConfig.APIHost, cfg.ServerConfig.APIPort), Handler: handler, - ReadTimeout: time.Second * 15, - ReadHeaderTimeout: time.Second * 15, - WriteTimeout: time.Second * 15, + ReadTimeout: time.Second * 10, + ReadHeaderTimeout: time.Second * 10, + WriteTimeout: time.Second * 10, }, cfg: cfg, svc: pkarrService,