diff --git a/go.mod b/go.mod index ed3b51bba..1ecd732ba 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/SkycoinProject/skywire-mainnet go 1.13 require ( - github.com/SkycoinProject/dmsg v0.0.0-20200306131535-fabb2c8177e9 + github.com/SkycoinProject/dmsg v0.0.0-20200306152741-acee74fa4514 github.com/SkycoinProject/skycoin v0.27.0 github.com/SkycoinProject/yamux v0.0.0-20191213015001-a36efeefbf6a github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 diff --git a/go.sum b/go.sum index 0242aab9b..254d67fd9 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/SkycoinProject/dmsg v0.0.0-20200306131535-fabb2c8177e9 h1:ce/1vcQhEX+8TkwX4PUUE2BVHA4sHNCPf8af7OVhPVE= -github.com/SkycoinProject/dmsg v0.0.0-20200306131535-fabb2c8177e9/go.mod h1:DzykXMLlx6Fx0fGjZsCIRas/MIvxW8DZpmDA6f2nCRk= +github.com/SkycoinProject/dmsg v0.0.0-20200306152741-acee74fa4514 h1:Ysxe5a/uGJq5eeSPhlIkS0Ft29LzoVv4waaN0VE4JXM= +github.com/SkycoinProject/dmsg v0.0.0-20200306152741-acee74fa4514/go.mod h1:DzykXMLlx6Fx0fGjZsCIRas/MIvxW8DZpmDA6f2nCRk= github.com/SkycoinProject/skycoin v0.26.0/go.mod h1:xqPLOKh5B6GBZlGA7B5IJfQmCy7mwimD9NlqxR3gMXo= github.com/SkycoinProject/skycoin v0.27.0 h1:N3IHxj8ossHOcsxLYOYugT+OaELLncYHJHxbbYLPPmY= github.com/SkycoinProject/skycoin v0.27.0/go.mod h1:xqPLOKh5B6GBZlGA7B5IJfQmCy7mwimD9NlqxR3gMXo= diff --git a/vendor/github.com/SkycoinProject/dmsg/disc/client.go b/vendor/github.com/SkycoinProject/dmsg/disc/client.go index d483f46d8..da8c2faef 100644 --- a/vendor/github.com/SkycoinProject/dmsg/disc/client.go +++ b/vendor/github.com/SkycoinProject/dmsg/disc/client.go @@ -36,6 +36,9 @@ type httpClient struct { // NewHTTP constructs a new APIClient that communicates with discovery via http. func NewHTTP(address string) APIClient { + log.WithField("func", "disc.NewHTTP"). + WithField("addr", address). + Debug("Created HTTP client.") return &httpClient{ client: http.Client{}, address: address, @@ -44,8 +47,8 @@ func NewHTTP(address string) APIClient { // Entry retrieves an entry associated with the given public key. func (c *httpClient) Entry(ctx context.Context, publicKey cipher.PubKey) (*Entry, error) { - var entry Entry endpoint := fmt.Sprintf("%s/dmsg-discovery/entry/%s", c.address, publicKey) + log := log.WithField("endpoint", endpoint) req, err := http.NewRequest(http.MethodGet, endpoint, nil) if err != nil { @@ -57,7 +60,7 @@ func (c *httpClient) Entry(ctx context.Context, publicKey cipher.PubKey) (*Entry if resp != nil { defer func() { if err := resp.Body.Close(); err != nil { - log.WithError(err).Warn("Failed to close response body") + log.WithError(err).Warn("Failed to close response body.") } }() } @@ -76,17 +79,18 @@ func (c *httpClient) Entry(ctx context.Context, publicKey cipher.PubKey) (*Entry return nil, errFromString(message.Message) } - err = json.NewDecoder(resp.Body).Decode(&entry) - if err != nil { + var entry Entry + if err := json.NewDecoder(resp.Body).Decode(&entry); err != nil { return nil, err } - return &entry, nil } // PostEntry creates a new Entry. func (c *httpClient) PostEntry(ctx context.Context, e *Entry) error { endpoint := c.address + "/dmsg-discovery/entry/" + log := log.WithField("endpoint", endpoint) + marshaledEntry, err := json.Marshal(e) if err != nil { return err @@ -104,12 +108,12 @@ func (c *httpClient) PostEntry(ctx context.Context, e *Entry) error { if resp != nil { defer func() { if err := resp.Body.Close(); err != nil { - log.WithError(err).Warn("Failed to close response body") + log.WithError(err).Warn("Failed to close response body.") } }() } if err != nil { - fmt.Println("req.Do err") + log.WithError(err).Error("Failed to perform request.") return err } @@ -124,7 +128,9 @@ func (c *httpClient) PostEntry(ctx context.Context, e *Entry) error { if err != nil { return err } - fmt.Println("response msg err") + log.WithField("resp_body", httpResponse.Message). + WithField("resp_status", resp.StatusCode). + Error() return errFromString(httpResponse.Message) } return nil diff --git a/vendor/github.com/SkycoinProject/dmsg/disc/entry.go b/vendor/github.com/SkycoinProject/dmsg/disc/entry.go index c3066e912..99e0589ca 100644 --- a/vendor/github.com/SkycoinProject/dmsg/disc/entry.go +++ b/vendor/github.com/SkycoinProject/dmsg/disc/entry.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "net/url" "strings" "time" @@ -44,22 +43,26 @@ var ( ErrValidationWrongTime = NewEntryValidationError("previous entry timestamp is not set before current entry timestamp") // ErrValidationServerAddress occurs in case when client want to advertise wrong Server address ErrValidationServerAddress = NewEntryValidationError("advertising localhost listening address is not allowed in production mode") + // ErrValidationEmptyServerAddress occurs when a server entry is submitted with an empty address. + ErrValidationEmptyServerAddress = NewEntryValidationError("server address cannot be empty") errReverseMap = map[string]error{ - ErrKeyNotFound.Error(): ErrKeyNotFound, - ErrNoAvailableServers.Error(): ErrNoAvailableServers, - ErrUnexpected.Error(): ErrUnexpected, - ErrUnauthorized.Error(): ErrUnauthorized, - ErrBadInput.Error(): ErrBadInput, - ErrValidationNonZeroSequence.Error(): ErrValidationNonZeroSequence, - ErrValidationNilEphemerals.Error(): ErrValidationNilEphemerals, - ErrValidationNilKeys.Error(): ErrValidationNilKeys, - ErrValidationNonNilEphemerals.Error(): ErrValidationNonNilEphemerals, - ErrValidationNoSignature.Error(): ErrValidationNoSignature, - ErrValidationNoVersion.Error(): ErrValidationNoVersion, - ErrValidationNoClientOrServer.Error(): ErrValidationNoClientOrServer, - ErrValidationWrongSequence.Error(): ErrValidationWrongSequence, - ErrValidationWrongTime.Error(): ErrValidationWrongTime, + ErrKeyNotFound.Error(): ErrKeyNotFound, + ErrNoAvailableServers.Error(): ErrNoAvailableServers, + ErrUnexpected.Error(): ErrUnexpected, + ErrUnauthorized.Error(): ErrUnauthorized, + ErrBadInput.Error(): ErrBadInput, + ErrValidationNonZeroSequence.Error(): ErrValidationNonZeroSequence, + ErrValidationNilEphemerals.Error(): ErrValidationNilEphemerals, + ErrValidationNilKeys.Error(): ErrValidationNilKeys, + ErrValidationNonNilEphemerals.Error(): ErrValidationNonNilEphemerals, + ErrValidationNoSignature.Error(): ErrValidationNoSignature, + ErrValidationNoVersion.Error(): ErrValidationNoVersion, + ErrValidationNoClientOrServer.Error(): ErrValidationNoClientOrServer, + ErrValidationWrongSequence.Error(): ErrValidationWrongSequence, + ErrValidationWrongTime.Error(): ErrValidationWrongTime, + ErrValidationServerAddress.Error(): ErrValidationServerAddress, + ErrValidationEmptyServerAddress.Error(): ErrValidationEmptyServerAddress, } ) @@ -251,10 +254,8 @@ func (e *Entry) Validate() error { return ErrValidationNoClientOrServer } - if e.Server != nil { - if _, err := url.Parse(e.Server.Address); err != nil { - return fmt.Errorf("failed to parse server.address: %v", err) - } + if e.Server != nil && e.Server.Address == "" { + return ErrValidationEmptyServerAddress } return nil