aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-03-23 01:20:33 +0800
committerFelix Lange <fjl@twurst.com>2017-03-23 03:49:15 +0800
commitc213fd1fd8bb624241da7fc98cf25098d8b92761 (patch)
tree7b109b0962b34d90d275a1dd1f64fbdba588bf9f /rpc
parent525116dbff916825463931361f75e75e955c12e2 (diff)
downloadgo-tangerine-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.gz
go-tangerine-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.zst
go-tangerine-c213fd1fd8bb624241da7fc98cf25098d8b92761.zip
all: import "context" instead of "golang.org/x/net/context"
There is no need to depend on the old context package now that the minimum Go version is 1.7. The move to "context" eliminates our weird vendoring setup. Some vendored code still uses golang.org/x/net/context and it is now vendored in the normal way. This change triggered new vet checks around context.WithTimeout which didn't fire with golang.org/x/net/context.
Diffstat (limited to 'rpc')
-rw-r--r--rpc/client.go2
-rw-r--r--rpc/client_context_go1.4.go60
-rw-r--r--rpc/client_context_go1.5.go61
-rw-r--r--rpc/client_context_go1.6.go55
-rw-r--r--rpc/client_context_go1.7.go51
-rw-r--r--rpc/client_example_test.go2
-rw-r--r--rpc/client_test.go2
-rw-r--r--rpc/http.go6
-rw-r--r--rpc/inproc.go3
-rw-r--r--rpc/ipc.go3
-rw-r--r--rpc/ipc_unix.go3
-rw-r--r--rpc/ipc_windows.go2
-rw-r--r--rpc/server.go3
-rw-r--r--rpc/server_test.go3
-rw-r--r--rpc/subscription.go3
-rw-r--r--rpc/subscription_test.go3
-rw-r--r--rpc/utils.go3
-rw-r--r--rpc/websocket.go19
18 files changed, 32 insertions, 252 deletions
diff --git a/rpc/client.go b/rpc/client.go
index 78a6fe789..2c35ba54a 100644
--- a/rpc/client.go
+++ b/rpc/client.go
@@ -19,6 +19,7 @@ package rpc
import (
"bytes"
"container/list"
+ "context"
"encoding/json"
"errors"
"fmt"
@@ -31,7 +32,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/log"
- "golang.org/x/net/context"
)
var (
diff --git a/rpc/client_context_go1.4.go b/rpc/client_context_go1.4.go
deleted file mode 100644
index ac956a17d..000000000
--- a/rpc/client_context_go1.4.go
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build !go1.5
-
-package rpc
-
-import (
- "net"
- "net/http"
- "time"
-
- "golang.org/x/net/context"
-)
-
-// In older versions of Go (below 1.5), dials cannot be canceled
-// via a channel or context. The context deadline can still applied.
-
-// contextDialer returns a dialer that applies the deadline value from the given context.
-func contextDialer(ctx context.Context) *net.Dialer {
- dialer := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
- if deadline, ok := ctx.Deadline(); ok {
- dialer.Deadline = deadline
- } else {
- dialer.Deadline = time.Now().Add(defaultDialTimeout)
- }
- return dialer
-}
-
-// dialContext connects to the given address, aborting the dial if ctx is canceled.
-func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
- return contextDialer(ctx).Dial(network, addr)
-}
-
-// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
-func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
- // Set Timeout on the client if the context has a deadline.
- // Note that there is no default timeout (unlike in contextDialer) because
- // the timeout applies to the entire request, including reads from body.
- if deadline, ok := ctx.Deadline(); ok {
- c2 := *c
- c2.Timeout = deadline.Sub(time.Now())
- c = &c2
- }
- req2 := *req
- return c, &req2
-}
diff --git a/rpc/client_context_go1.5.go b/rpc/client_context_go1.5.go
deleted file mode 100644
index 4a007d9f8..000000000
--- a/rpc/client_context_go1.5.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build go1.5,!go1.6
-
-package rpc
-
-import (
- "net"
- "net/http"
- "time"
-
- "golang.org/x/net/context"
-)
-
-// In Go 1.5, dials cannot be canceled via a channel or context. The context deadline can
-// still be applied. Go 1.5 adds the ability to cancel HTTP requests via a channel.
-
-// contextDialer returns a dialer that applies the deadline value from the given context.
-func contextDialer(ctx context.Context) *net.Dialer {
- dialer := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
- if deadline, ok := ctx.Deadline(); ok {
- dialer.Deadline = deadline
- } else {
- dialer.Deadline = time.Now().Add(defaultDialTimeout)
- }
- return dialer
-}
-
-// dialContext connects to the given address, aborting the dial if ctx is canceled.
-func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
- return contextDialer(ctx).Dial(network, addr)
-}
-
-// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
-func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
- // Set Timeout on the client if the context has a deadline.
- // Note that there is no default timeout (unlike in contextDialer) because
- // the timeout applies to the entire request, including reads from body.
- if deadline, ok := ctx.Deadline(); ok {
- c2 := *c
- c2.Timeout = deadline.Sub(time.Now())
- c = &c2
- }
- req2 := *req
- req2.Cancel = ctx.Done()
- return c, &req2
-}
diff --git a/rpc/client_context_go1.6.go b/rpc/client_context_go1.6.go
deleted file mode 100644
index 67777ddc6..000000000
--- a/rpc/client_context_go1.6.go
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build go1.6,!go1.7
-
-package rpc
-
-import (
- "net"
- "net/http"
- "time"
-
- "golang.org/x/net/context"
-)
-
-// In Go 1.6, net.Dialer gained the ability to cancel via a channel.
-
-// contextDialer returns a dialer that applies the deadline value from the given context.
-func contextDialer(ctx context.Context) *net.Dialer {
- dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
- if deadline, ok := ctx.Deadline(); ok {
- dialer.Deadline = deadline
- } else {
- dialer.Deadline = time.Now().Add(defaultDialTimeout)
- }
- return dialer
-}
-
-// dialContext connects to the given address, aborting the dial if ctx is canceled.
-func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
- return contextDialer(ctx).Dial(network, addr)
-}
-
-// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
-func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
- // We set Timeout on the client for Go <= 1.5. There
- // is no need to do that here because the dial will be canceled
- // by package http.
- req2 := *req
- req2.Cancel = ctx.Done()
- return c, &req2
-}
diff --git a/rpc/client_context_go1.7.go b/rpc/client_context_go1.7.go
deleted file mode 100644
index 56ce12ab8..000000000
--- a/rpc/client_context_go1.7.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build go1.7
-
-package rpc
-
-import (
- "context"
- "net"
- "net/http"
- "time"
-)
-
-// In Go 1.7, context moved into the standard library and support
-// for cancelation via context was added to net.Dialer and http.Request.
-
-// contextDialer returns a dialer that applies the deadline value from the given context.
-func contextDialer(ctx context.Context) *net.Dialer {
- dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
- if deadline, ok := ctx.Deadline(); ok {
- dialer.Deadline = deadline
- } else {
- dialer.Deadline = time.Now().Add(defaultDialTimeout)
- }
- return dialer
-}
-
-// dialContext connects to the given address, aborting the dial if ctx is canceled.
-func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
- d := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
- return d.DialContext(ctx, network, addr)
-}
-
-// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
-func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
- return c, req.WithContext(ctx)
-}
diff --git a/rpc/client_example_test.go b/rpc/client_example_test.go
index 3462b3685..8276a9ead 100644
--- a/rpc/client_example_test.go
+++ b/rpc/client_example_test.go
@@ -17,12 +17,12 @@
package rpc_test
import (
+ "context"
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum/rpc"
- "golang.org/x/net/context"
)
// In this example, our client whishes to track the latest 'block number'
diff --git a/rpc/client_test.go b/rpc/client_test.go
index 407ed9c06..41471dcea 100644
--- a/rpc/client_test.go
+++ b/rpc/client_test.go
@@ -17,6 +17,7 @@
package rpc
import (
+ "context"
"fmt"
"math/rand"
"net"
@@ -31,7 +32,6 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/log"
- "golang.org/x/net/context"
)
func TestClientRequest(t *testing.T) {
diff --git a/rpc/http.go b/rpc/http.go
index 5a0770231..89175b149 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -18,6 +18,7 @@ package rpc
import (
"bytes"
+ "context"
"encoding/json"
"fmt"
"io"
@@ -29,7 +30,6 @@ import (
"time"
"github.com/rs/cors"
- "golang.org/x/net/context"
)
const (
@@ -115,11 +115,11 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
if err != nil {
return nil, err
}
- client, req := requestWithContext(hc.client, hc.req, ctx)
+ req := hc.req.WithContext(ctx)
req.Body = ioutil.NopCloser(bytes.NewReader(body))
req.ContentLength = int64(len(body))
- resp, err := client.Do(req)
+ resp, err := hc.client.Do(req)
if err != nil {
return nil, err
}
diff --git a/rpc/inproc.go b/rpc/inproc.go
index f72b97497..595a7ca65 100644
--- a/rpc/inproc.go
+++ b/rpc/inproc.go
@@ -17,9 +17,8 @@
package rpc
import (
+ "context"
"net"
-
- "golang.org/x/net/context"
)
// NewInProcClient attaches an in-process connection to the given RPC server.
diff --git a/rpc/ipc.go b/rpc/ipc.go
index 3c86d711c..8de18a56f 100644
--- a/rpc/ipc.go
+++ b/rpc/ipc.go
@@ -17,12 +17,11 @@
package rpc
import (
+ "context"
"fmt"
"net"
"github.com/ethereum/go-ethereum/log"
-
- "golang.org/x/net/context"
)
// CreateIPCListener creates an listener, on Unix platforms this is a unix socket, on
diff --git a/rpc/ipc_unix.go b/rpc/ipc_unix.go
index a25b21627..0851ea61e 100644
--- a/rpc/ipc_unix.go
+++ b/rpc/ipc_unix.go
@@ -19,11 +19,10 @@
package rpc
import (
+ "context"
"net"
"os"
"path/filepath"
-
- "golang.org/x/net/context"
)
// ipcListen will create a Unix socket on the given endpoint.
diff --git a/rpc/ipc_windows.go b/rpc/ipc_windows.go
index 68234d215..ca56a3ce4 100644
--- a/rpc/ipc_windows.go
+++ b/rpc/ipc_windows.go
@@ -19,10 +19,10 @@
package rpc
import (
+ "context"
"net"
"time"
- "golang.org/x/net/context"
"gopkg.in/natefinch/npipe.v2"
)
diff --git a/rpc/server.go b/rpc/server.go
index 4f9ce541e..ca7e3c01a 100644
--- a/rpc/server.go
+++ b/rpc/server.go
@@ -17,14 +17,13 @@
package rpc
import (
+ "context"
"fmt"
"reflect"
"runtime"
"sync/atomic"
"github.com/ethereum/go-ethereum/log"
-
- "golang.org/x/net/context"
"gopkg.in/fatih/set.v0"
)
diff --git a/rpc/server_test.go b/rpc/server_test.go
index c3c88fab7..90d62f26d 100644
--- a/rpc/server_test.go
+++ b/rpc/server_test.go
@@ -17,13 +17,12 @@
package rpc
import (
+ "context"
"encoding/json"
"net"
"reflect"
"testing"
"time"
-
- "golang.org/x/net/context"
)
type Service struct{}
diff --git a/rpc/subscription.go b/rpc/subscription.go
index bcdc3cdfc..9ab6af9e1 100644
--- a/rpc/subscription.go
+++ b/rpc/subscription.go
@@ -17,10 +17,9 @@
package rpc
import (
+ "context"
"errors"
"sync"
-
- "golang.org/x/net/context"
)
var (
diff --git a/rpc/subscription_test.go b/rpc/subscription_test.go
index 00c4e0e35..345b4e5f2 100644
--- a/rpc/subscription_test.go
+++ b/rpc/subscription_test.go
@@ -17,13 +17,12 @@
package rpc
import (
+ "context"
"encoding/json"
"net"
"sync"
"testing"
"time"
-
- "golang.org/x/net/context"
)
type NotificationTestService struct {
diff --git a/rpc/utils.go b/rpc/utils.go
index c249e9b4a..2506c4833 100644
--- a/rpc/utils.go
+++ b/rpc/utils.go
@@ -18,6 +18,7 @@ package rpc
import (
"bufio"
+ "context"
crand "crypto/rand"
"encoding/binary"
"encoding/hex"
@@ -29,8 +30,6 @@ import (
"time"
"unicode"
"unicode/utf8"
-
- "golang.org/x/net/context"
)
var (
diff --git a/rpc/websocket.go b/rpc/websocket.go
index f4271fda8..587010820 100644
--- a/rpc/websocket.go
+++ b/rpc/websocket.go
@@ -17,6 +17,7 @@
package rpc
import (
+ "context"
"crypto/tls"
"fmt"
"net"
@@ -24,10 +25,9 @@ import (
"net/url"
"os"
"strings"
+ "time"
"github.com/ethereum/go-ethereum/log"
-
- "golang.org/x/net/context"
"golang.org/x/net/websocket"
"gopkg.in/fatih/set.v0"
)
@@ -150,3 +150,18 @@ func wsDialAddress(location *url.URL) string {
}
return location.Host
}
+
+func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
+ d := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
+ return d.DialContext(ctx, network, addr)
+}
+
+func contextDialer(ctx context.Context) *net.Dialer {
+ dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
+ if deadline, ok := ctx.Deadline(); ok {
+ dialer.Deadline = deadline
+ } else {
+ dialer.Deadline = time.Now().Add(defaultDialTimeout)
+ }
+ return dialer
+}