Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MakeHTTPTransport #1065

Merged
merged 3 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/schollz/progressbar/v2 v2.15.0
github.com/shirou/gopsutil/v3 v3.21.4
github.com/sirupsen/logrus v1.8.1
github.com/skycoin/dmsg v0.0.0-20211229130221-70e9ab64c1be
github.com/skycoin/dmsg v0.0.0-20220125112430-1dfce6ea8ef3
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/yamux v0.0.0-20200803175205-571ceb89da9f
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5k
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skycoin/dmsg v0.0.0-20211229130221-70e9ab64c1be h1:M+f0VZ7I7Yt/sI4tcKFIpU0nPWdRKz5e0+xLjvjm6iI=
github.com/skycoin/dmsg v0.0.0-20211229130221-70e9ab64c1be/go.mod h1:EgRg8fy5RjF67OJlh9w+vhq3+Phyn6AXKSedkzhf1ww=
github.com/skycoin/dmsg v0.0.0-20220125112430-1dfce6ea8ef3 h1:Ja0OyTBk00akywqJbPpPV6wyBX9NtjpyQD64G7oH4RQ=
github.com/skycoin/dmsg v0.0.0-20220125112430-1dfce6ea8ef3/go.mod h1:EgRg8fy5RjF67OJlh9w+vhq3+Phyn6AXKSedkzhf1ww=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.26.0/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
Expand Down
16 changes: 9 additions & 7 deletions internal/httpauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (c *Client) do(client *http.Client, req *http.Request) (*http.Response, err
return nil, err
}

isNonceValid, err := isNonceValid(resp)
resp, isNonceValid, err := isNonceValid(resp)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -259,26 +259,28 @@ func (c *Client) IncrementNonce() {
// isNonceValid checks if `res` contains an invalid nonce error.
// The error is occurred if status code equals to `http.StatusUnauthorized`
// and body contains `invalidNonceErrorMessage`.
func isNonceValid(res *http.Response) (bool, error) {
func isNonceValid(res *http.Response) (*http.Response, bool, error) {
var serverResponse HTTPResponse
var auxResp http.Response

auxRespBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
return nil, false, err
}
if err := res.Body.Close(); err != nil {
return false, err
return nil, false, err
}
res.Body = ioutil.NopCloser(bytes.NewBuffer(auxRespBody))
auxResp = *res
auxResp.Body = ioutil.NopCloser(bytes.NewBuffer(auxRespBody))

if err := json.Unmarshal(auxRespBody, &serverResponse); err != nil || serverResponse.Error == nil {
return true, nil
return &auxResp, true, nil
}

isAuthorized := serverResponse.Error.Code != http.StatusUnauthorized
hasValidNonce := serverResponse.Error.Message != invalidNonceErrorMessage

return isAuthorized && hasValidNonce, nil
return &auxResp, isAuthorized && hasValidNonce, nil
}

func sanitizedAddr(addr string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func initDmsgHTTP(ctx context.Context, v *Visor, log *logging.Logger) error {
return fmt.Errorf("failed to start dmsg: %w", err)
}

dmsgHTTP := http.Client{Transport: dmsghttp.MakeHTTPTransport(dmsgDC)}
dmsgHTTP := http.Client{Transport: dmsghttp.MakeHTTPTransport(ctx, dmsgDC)}

v.pushCloseStack("dmsg_http", func() error {
closeDmsgDC()
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/skycoin/dmsg/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/skycoin/dmsg/dmsgget/dmsgget.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions vendor/github.com/skycoin/dmsg/dmsghttp/http_transport.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions vendor/github.com/skycoin/dmsg/dmsghttp/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ github.com/shirou/gopsutil/v3/process
## explicit; go 1.13
github.com/sirupsen/logrus
github.com/sirupsen/logrus/hooks/syslog
# github.com/skycoin/dmsg v0.0.0-20211229130221-70e9ab64c1be
# github.com/skycoin/dmsg v0.0.0-20220125112430-1dfce6ea8ef3
## explicit; go 1.16
github.com/skycoin/dmsg
github.com/skycoin/dmsg/buildinfo
Expand Down