mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Move iputil and httpuil pkgs into network pkg (#9621)
* Add network pkg * Go fmt * Update discovery_test.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -56,6 +56,7 @@ go_library(
|
||||
"//config/features:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//monitoring/tracing:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/metadata:go_default_library",
|
||||
"//proto/prysm/v1alpha1/wrapper:go_default_library",
|
||||
@@ -63,7 +64,6 @@ go_library(
|
||||
"//shared:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/fileutil:go_default_library",
|
||||
"//shared/iputils:go_default_library",
|
||||
"//shared/p2putils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/runutil:go_default_library",
|
||||
@@ -142,6 +142,7 @@ go_test(
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/p2p/types:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/wrapper:go_default_library",
|
||||
@@ -149,7 +150,6 @@ go_test(
|
||||
"//runtime/version:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/iputils:go_default_library",
|
||||
"//shared/p2putils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
|
||||
@@ -29,12 +29,12 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/scorers"
|
||||
testp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
prysmNetwork "github.com/prysmaticlabs/prysm/network"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -48,7 +48,7 @@ func init() {
|
||||
}
|
||||
|
||||
func createAddrAndPrivKey(t *testing.T) (net.IP, *ecdsa.PrivateKey) {
|
||||
ip, err := iputils.ExternalIPv4()
|
||||
ip, err := prysmNetwork.ExternalIPv4()
|
||||
require.NoError(t, err, "Could not get ip")
|
||||
ipAddr := net.ParseIP(ip)
|
||||
temp := t.TempDir()
|
||||
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/metadata"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -149,7 +149,7 @@ func metaDataFromConfig(cfg *Config) (metadata.Metadata, error) {
|
||||
|
||||
// Retrieves an external ipv4 address and converts into a libp2p formatted value.
|
||||
func ipAddr() net.IP {
|
||||
ip, err := iputils.ExternalIP()
|
||||
ip, err := network.ExternalIP()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not get IPv4 address: %v", err)
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ go_library(
|
||||
"//crypto/hash:go_default_library",
|
||||
"//monitoring/clientstats:go_default_library",
|
||||
"//monitoring/tracing:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//network/authorization:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/httputils:go_default_library",
|
||||
"//shared/httputils/authorizationmethod:go_default_library",
|
||||
"//shared/logutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//time:go_default_library",
|
||||
@@ -86,11 +86,11 @@ go_test(
|
||||
"//contracts/deposit-contract:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//monitoring/clientstats:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//network/authorization:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/httputils:go_default_library",
|
||||
"//shared/httputils/authorizationmethod:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
|
||||
@@ -4,16 +4,16 @@ import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||
)
|
||||
|
||||
// HttpEndpoint extracts an httputils.Endpoint from the provider parameter.
|
||||
func HttpEndpoint(eth1Provider string) httputils.Endpoint {
|
||||
endpoint := httputils.Endpoint{
|
||||
func HttpEndpoint(eth1Provider string) network.Endpoint {
|
||||
endpoint := network.Endpoint{
|
||||
Url: "",
|
||||
Auth: httputils.AuthorizationData{
|
||||
Method: authorizationmethod.None,
|
||||
Auth: network.AuthorizationData{
|
||||
Method: authorization.None,
|
||||
Value: "",
|
||||
}}
|
||||
|
||||
@@ -24,24 +24,24 @@ func HttpEndpoint(eth1Provider string) httputils.Endpoint {
|
||||
"ETH1 endpoint string can contain one comma for specifying the authorization header to access the provider."+
|
||||
" String contains too many commas: %d. Skipping authorization.", len(authValues)-1)
|
||||
} else if len(authValues) == 2 {
|
||||
switch httputils.Method(strings.TrimSpace(authValues[1])) {
|
||||
case authorizationmethod.Basic:
|
||||
switch network.Method(strings.TrimSpace(authValues[1])) {
|
||||
case authorization.Basic:
|
||||
basicAuthValues := strings.Split(strings.TrimSpace(authValues[1]), " ")
|
||||
if len(basicAuthValues) != 2 {
|
||||
log.Errorf("Basic Authentication has incorrect format. Skipping authorization.")
|
||||
} else {
|
||||
endpoint.Auth.Method = authorizationmethod.Basic
|
||||
endpoint.Auth.Method = authorization.Basic
|
||||
endpoint.Auth.Value = base64.StdEncoding.EncodeToString([]byte(basicAuthValues[1]))
|
||||
}
|
||||
case authorizationmethod.Bearer:
|
||||
case authorization.Bearer:
|
||||
bearerAuthValues := strings.Split(strings.TrimSpace(authValues[1]), " ")
|
||||
if len(bearerAuthValues) != 2 {
|
||||
log.Errorf("Bearer Authentication has incorrect format. Skipping authorization.")
|
||||
} else {
|
||||
endpoint.Auth.Method = authorizationmethod.Bearer
|
||||
endpoint.Auth.Method = authorization.Bearer
|
||||
endpoint.Auth.Value = bearerAuthValues[1]
|
||||
}
|
||||
case authorizationmethod.None:
|
||||
case authorization.None:
|
||||
log.Errorf("Authorization has incorrect format or authorization type is not supported.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package powchain
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
@@ -15,60 +15,60 @@ func TestHttpEndpoint(t *testing.T) {
|
||||
t.Run("URL", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url)
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
})
|
||||
t.Run("URL with separator", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ",")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
})
|
||||
t.Run("URL with whitespace", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(" " + url + " ,")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
})
|
||||
t.Run("Basic auth", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ",Basic username:password")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.Basic, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.Basic, endpoint.Auth.Method)
|
||||
assert.Equal(t, "dXNlcm5hbWU6cGFzc3dvcmQ=", endpoint.Auth.Value)
|
||||
})
|
||||
t.Run("Basic auth with whitespace", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ", Basic username:password ")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.Basic, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.Basic, endpoint.Auth.Method)
|
||||
assert.Equal(t, "dXNlcm5hbWU6cGFzc3dvcmQ=", endpoint.Auth.Value)
|
||||
})
|
||||
t.Run("Basic auth with incorrect format", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
endpoint := HttpEndpoint(url + ",Basic username:password foo")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
assert.LogsContain(t, hook, "Skipping authorization")
|
||||
})
|
||||
t.Run("Bearer auth", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ",Bearer token")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.Bearer, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.Bearer, endpoint.Auth.Method)
|
||||
assert.Equal(t, "token", endpoint.Auth.Value)
|
||||
})
|
||||
t.Run("Bearer auth with whitespace", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ", Bearer token ")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.Bearer, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.Bearer, endpoint.Auth.Method)
|
||||
assert.Equal(t, "token", endpoint.Auth.Value)
|
||||
})
|
||||
t.Run("Bearer auth with incorrect format", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
endpoint := HttpEndpoint(url + ",Bearer token foo")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
assert.LogsContain(t, hook, "Skipping authorization")
|
||||
})
|
||||
t.Run("Too many separators", func(t *testing.T) {
|
||||
endpoint := HttpEndpoint(url + ",Bearer token,foo")
|
||||
assert.Equal(t, url, endpoint.Url)
|
||||
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
||||
assert.Equal(t, authorization.None, endpoint.Auth.Method)
|
||||
assert.LogsContain(t, hook, "Skipping authorization")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/container/trie"
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/clientstats"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
protodb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/shared/logutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
@@ -134,8 +134,8 @@ type Service struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
headTicker *time.Ticker
|
||||
httpEndpoints []httputils.Endpoint
|
||||
currHttpEndpoint httputils.Endpoint
|
||||
httpEndpoints []network.Endpoint
|
||||
currHttpEndpoint network.Endpoint
|
||||
httpLogger bind.ContractFilterer
|
||||
eth1DataFetcher RPCDataFetcher
|
||||
rpcClient RPCClient
|
||||
@@ -182,13 +182,13 @@ func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error
|
||||
}
|
||||
|
||||
stringEndpoints := dedupEndpoints(config.HttpEndpoints)
|
||||
endpoints := make([]httputils.Endpoint, len(stringEndpoints))
|
||||
endpoints := make([]network.Endpoint, len(stringEndpoints))
|
||||
for i, e := range stringEndpoints {
|
||||
endpoints[i] = HttpEndpoint(e)
|
||||
}
|
||||
|
||||
// Select first http endpoint in the provided list.
|
||||
var currEndpoint httputils.Endpoint
|
||||
var currEndpoint network.Endpoint
|
||||
if len(config.HttpEndpoints) > 0 {
|
||||
currEndpoint = endpoints[0]
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func (s *Service) updateBeaconNodeStats() {
|
||||
s.bsUpdater.Update(bs)
|
||||
}
|
||||
|
||||
func (s *Service) updateCurrHttpEndpoint(endpoint httputils.Endpoint) {
|
||||
func (s *Service) updateCurrHttpEndpoint(endpoint network.Endpoint) {
|
||||
s.currHttpEndpoint = endpoint
|
||||
s.updateBeaconNodeStats()
|
||||
}
|
||||
@@ -410,12 +410,12 @@ func (s *Service) connectToPowChain() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) dialETH1Nodes(endpoint httputils.Endpoint) (*ethclient.Client, *gethRPC.Client, error) {
|
||||
func (s *Service) dialETH1Nodes(endpoint network.Endpoint) (*ethclient.Client, *gethRPC.Client, error) {
|
||||
httpRPCClient, err := gethRPC.Dial(endpoint.Url)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if endpoint.Auth.Method != authorizationmethod.None {
|
||||
if endpoint.Auth.Method != authorization.None {
|
||||
header, err := endpoint.Auth.ToHeaderValue()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -20,10 +20,10 @@ import (
|
||||
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/clientstats"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
protodb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
@@ -570,7 +570,7 @@ func TestServiceFallbackCorrectly(t *testing.T) {
|
||||
assert.Equal(t, firstEndpoint, s1.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
assert.Equal(t, false, mbs.lastBS.SyncEth1FallbackConfigured, "SyncEth1FallbackConfigured in clientstats update should be false when only 1 endpoint is configured")
|
||||
|
||||
s1.httpEndpoints = append(s1.httpEndpoints, httputils.Endpoint{Url: secondEndpoint})
|
||||
s1.httpEndpoints = append(s1.httpEndpoints, network.Endpoint{Url: secondEndpoint})
|
||||
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, secondEndpoint, s1.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
@@ -579,7 +579,7 @@ func TestServiceFallbackCorrectly(t *testing.T) {
|
||||
thirdEndpoint := "C"
|
||||
fourthEndpoint := "D"
|
||||
|
||||
s1.httpEndpoints = append(s1.httpEndpoints, httputils.Endpoint{Url: thirdEndpoint}, httputils.Endpoint{Url: fourthEndpoint})
|
||||
s1.httpEndpoints = append(s1.httpEndpoints, network.Endpoint{Url: thirdEndpoint}, network.Endpoint{Url: fourthEndpoint})
|
||||
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, thirdEndpoint, s1.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
|
||||
26
network/BUILD.bazel
Normal file
26
network/BUILD.bazel
Normal file
@@ -0,0 +1,26 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"endpoint.go",
|
||||
"external_ip.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/network",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//network/authorization:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"endpoint_test.go",
|
||||
"external_ip_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//network/authorization:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -3,6 +3,6 @@ load("@prysm//tools/go:def.bzl", "go_library")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["authorization_method.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod",
|
||||
importpath = "github.com/prysmaticlabs/prysm/network/authorization",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
package authorizationmethod
|
||||
package authorization
|
||||
|
||||
// AuthorizationMethod is an authorization method such as 'Basic' or 'Bearer'.
|
||||
type AuthorizationMethod uint8
|
||||
@@ -1,10 +1,10 @@
|
||||
package httputils
|
||||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||
)
|
||||
|
||||
// Endpoint is an endpoint with authorization data.
|
||||
@@ -15,7 +15,7 @@ type Endpoint struct {
|
||||
|
||||
// AuthorizationData holds all information necessary to authorize with HTTP.
|
||||
type AuthorizationData struct {
|
||||
Method authorizationmethod.AuthorizationMethod
|
||||
Method authorization.AuthorizationMethod
|
||||
Value string
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ func (d AuthorizationData) Equals(other AuthorizationData) bool {
|
||||
// ToHeaderValue retrieves the value of the authorization header from AuthorizationData.
|
||||
func (d *AuthorizationData) ToHeaderValue() (string, error) {
|
||||
switch d.Method {
|
||||
case authorizationmethod.Basic:
|
||||
case authorization.Basic:
|
||||
return "Basic " + d.Value, nil
|
||||
case authorizationmethod.Bearer:
|
||||
case authorization.Bearer:
|
||||
return "Bearer " + d.Value, nil
|
||||
case authorizationmethod.None:
|
||||
case authorization.None:
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ func (d *AuthorizationData) ToHeaderValue() (string, error) {
|
||||
}
|
||||
|
||||
// Method returns the authorizationmethod.AuthorizationMethod corresponding with the parameter value.
|
||||
func Method(auth string) authorizationmethod.AuthorizationMethod {
|
||||
func Method(auth string) authorization.AuthorizationMethod {
|
||||
if strings.HasPrefix(strings.ToLower(auth), "basic") {
|
||||
return authorizationmethod.Basic
|
||||
return authorization.Basic
|
||||
}
|
||||
if strings.HasPrefix(strings.ToLower(auth), "bearer") {
|
||||
return authorizationmethod.Bearer
|
||||
return authorization.Bearer
|
||||
}
|
||||
return authorizationmethod.None
|
||||
return authorization.None
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package httputils
|
||||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func TestToHeaderValue(t *testing.T) {
|
||||
t.Run("None", func(t *testing.T) {
|
||||
data := &AuthorizationData{
|
||||
Method: authorizationmethod.None,
|
||||
Method: authorization.None,
|
||||
Value: "foo",
|
||||
}
|
||||
header, err := data.ToHeaderValue()
|
||||
@@ -20,7 +20,7 @@ func TestToHeaderValue(t *testing.T) {
|
||||
})
|
||||
t.Run("Basic", func(t *testing.T) {
|
||||
data := &AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "foo",
|
||||
}
|
||||
header, err := data.ToHeaderValue()
|
||||
@@ -29,7 +29,7 @@ func TestToHeaderValue(t *testing.T) {
|
||||
})
|
||||
t.Run("Bearer", func(t *testing.T) {
|
||||
data := &AuthorizationData{
|
||||
Method: authorizationmethod.Bearer,
|
||||
Method: authorization.Bearer,
|
||||
Value: "foo",
|
||||
}
|
||||
header, err := data.ToHeaderValue()
|
||||
@@ -49,25 +49,25 @@ func TestToHeaderValue(t *testing.T) {
|
||||
func TestMethod(t *testing.T) {
|
||||
t.Run("None", func(t *testing.T) {
|
||||
method := Method("")
|
||||
assert.Equal(t, authorizationmethod.None, method)
|
||||
assert.Equal(t, authorization.None, method)
|
||||
method = Method("foo")
|
||||
assert.Equal(t, authorizationmethod.None, method)
|
||||
assert.Equal(t, authorization.None, method)
|
||||
})
|
||||
t.Run("Basic", func(t *testing.T) {
|
||||
method := Method("Basic")
|
||||
assert.Equal(t, authorizationmethod.Basic, method)
|
||||
assert.Equal(t, authorization.Basic, method)
|
||||
})
|
||||
t.Run("Basic different text case", func(t *testing.T) {
|
||||
method := Method("bAsIc")
|
||||
assert.Equal(t, authorizationmethod.Basic, method)
|
||||
assert.Equal(t, authorization.Basic, method)
|
||||
})
|
||||
t.Run("Bearer", func(t *testing.T) {
|
||||
method := Method("Bearer")
|
||||
assert.Equal(t, authorizationmethod.Bearer, method)
|
||||
assert.Equal(t, authorization.Bearer, method)
|
||||
})
|
||||
t.Run("Bearer different text case", func(t *testing.T) {
|
||||
method := Method("bEaReR")
|
||||
assert.Equal(t, authorizationmethod.Bearer, method)
|
||||
assert.Equal(t, authorization.Bearer, method)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestEndpointEquals(t *testing.T) {
|
||||
e := Endpoint{
|
||||
Url: "Url",
|
||||
Auth: AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "Basic username:password",
|
||||
},
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func TestEndpointEquals(t *testing.T) {
|
||||
other := Endpoint{
|
||||
Url: "Url",
|
||||
Auth: AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "Basic username:password",
|
||||
},
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func TestEndpointEquals(t *testing.T) {
|
||||
other := Endpoint{
|
||||
Url: "Different",
|
||||
Auth: AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "Basic username:password",
|
||||
},
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func TestEndpointEquals(t *testing.T) {
|
||||
other := Endpoint{
|
||||
Url: "Url",
|
||||
Auth: AuthorizationData{
|
||||
Method: authorizationmethod.Bearer,
|
||||
Method: authorization.Bearer,
|
||||
Value: "Bearer token",
|
||||
},
|
||||
}
|
||||
@@ -114,27 +114,27 @@ func TestEndpointEquals(t *testing.T) {
|
||||
|
||||
func TestAuthorizationDataEquals(t *testing.T) {
|
||||
d := AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "username:password",
|
||||
}
|
||||
|
||||
t.Run("equal", func(t *testing.T) {
|
||||
other := AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "username:password",
|
||||
}
|
||||
assert.Equal(t, true, d.Equals(other))
|
||||
})
|
||||
t.Run("different method", func(t *testing.T) {
|
||||
other := AuthorizationData{
|
||||
Method: authorizationmethod.None,
|
||||
Method: authorization.None,
|
||||
Value: "username:password",
|
||||
}
|
||||
assert.Equal(t, false, d.Equals(other))
|
||||
})
|
||||
t.Run("different value", func(t *testing.T) {
|
||||
other := AuthorizationData{
|
||||
Method: authorizationmethod.Basic,
|
||||
Method: authorization.Basic,
|
||||
Value: "different:different",
|
||||
}
|
||||
assert.Equal(t, false, d.Equals(other))
|
||||
@@ -1,5 +1,5 @@
|
||||
// Package iputils contains useful functions for ip address formatting.
|
||||
package iputils
|
||||
package network
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -1,11 +1,11 @@
|
||||
package iputils_test
|
||||
package network_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func TestExternalIPv4(t *testing.T) {
|
||||
// Regular expression format for IPv4
|
||||
IPv4Format := `\.\d{1,3}\.\d{1,3}\b`
|
||||
test, err := iputils.ExternalIPv4()
|
||||
test, err := network.ExternalIPv4()
|
||||
require.NoError(t, err)
|
||||
|
||||
valid := regexp.MustCompile(IPv4Format)
|
||||
@@ -21,7 +21,7 @@ func TestExternalIPv4(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetrieveIP(t *testing.T) {
|
||||
ip, err := iputils.ExternalIP()
|
||||
ip, err := network.ExternalIP()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestSortAddresses(t *testing.T) {
|
||||
{0x03, 0x89, 0x33, 0x13},
|
||||
}
|
||||
|
||||
sortedAddrs := iputils.SortAddresses(testAddresses)
|
||||
sortedAddrs := network.SortAddresses(testAddresses)
|
||||
assert.Equal(t, true, sortedAddrs[0].To4() != nil, "expected ipv4 address")
|
||||
assert.Equal(t, true, sortedAddrs[1].To4() != nil, "expected ipv4 address")
|
||||
assert.Equal(t, true, sortedAddrs[2].To4() != nil, "expected ipv4 address")
|
||||
@@ -1,20 +1 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["endpoint.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/httputils",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//shared/httputils/authorizationmethod:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["endpoint_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//shared/httputils/authorizationmethod:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,20 +1 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["external_ip.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/iputils",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["external_ip_test.go"],
|
||||
tags = ["requires-network"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,11 +11,11 @@ go_library(
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//runtime/maxprocs:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/iputils:go_default_library",
|
||||
"//shared/logutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/runutil:go_default_library",
|
||||
@@ -68,8 +68,8 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
flaky = True,
|
||||
deps = [
|
||||
"//network:go_default_library",
|
||||
"//runtime/maxprocs:go_default_library",
|
||||
"//shared/iputils:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/discover:go_default_library",
|
||||
|
||||
@@ -33,11 +33,11 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
_ "github.com/prysmaticlabs/prysm/runtime/maxprocs"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/logutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
@@ -98,7 +98,7 @@ func main() {
|
||||
}
|
||||
cfg.Bootnodes = []*enode.Node{node}
|
||||
}
|
||||
ipAddr, err := iputils.ExternalIP()
|
||||
ipAddr, err := network.ExternalIP()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/prysmaticlabs/prysm/network"
|
||||
_ "github.com/prysmaticlabs/prysm/runtime/maxprocs"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestBootnode_OK(t *testing.T) {
|
||||
ipAddr, err := iputils.ExternalIPv4()
|
||||
ipAddr, err := network.ExternalIPv4()
|
||||
require.NoError(t, err)
|
||||
privKey := extractPrivateKey()
|
||||
cfg := discover.Config{
|
||||
|
||||
Reference in New Issue
Block a user