network

package
v0.0.1-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2024 License: Apache-2.0, MIT, GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package network contains useful functions for ip address formatting.

Index

Constants

View Source
const DefaultRPCHTTPTimeout = time.Second * 30

DefaultRPCHTTPTimeout for HTTP requests via an RPC connection to an execution node.

Variables

This section is empty.

Functions

func ExternalIP

func ExternalIP() (string, error)

ExternalIP returns the first IPv4/IPv6 available.

func ExternalIPv4

func ExternalIPv4() (string, error)

ExternalIPv4 returns the first IPv4 available.

func IPAddr

func IPAddr() net.IP

IPAddr gets the external ipv4 address and converts into a libp2p formatted value.

func Method

Method returns the authorizationmethod.AuthorizationMethod corresponding with the parameter value.

func NewExecutionRPCClient

func NewExecutionRPCClient(ctx context.Context, endpoint Endpoint) (*gethRPC.Client, error)

func NewHttpClientWithSecret

func NewHttpClientWithSecret(secret string) *http.Client

NewHttpClientWithSecret returns a http client that utilizes jwt authentication.

func SortAddresses

func SortAddresses(ipAddrs []net.IP) []net.IP

SortAddresses sorts a set of addresses in the order of ipv4 -> ipv6.

func WriteError

func WriteError(w http.ResponseWriter, errJson *DefaultErrorJson)

WriteError writes the error by manipulating headers and the body of the final response.

func WriteJson

func WriteJson(w http.ResponseWriter, v any)

WriteJson writes the response message in JSON format.

Types

type AuthorizationData

type AuthorizationData struct {
	Method authorization.AuthorizationMethod
	Value  string
}

AuthorizationData holds all information necessary to authorize with HTTP.

func (AuthorizationData) Equals

func (d AuthorizationData) Equals(other AuthorizationData) bool

Equals compares two authorization data objects for equality.

func (*AuthorizationData) ToHeaderValue

func (d *AuthorizationData) ToHeaderValue() (string, error)

ToHeaderValue retrieves the value of the authorization header from AuthorizationData.

type DefaultErrorJson

type DefaultErrorJson struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

DefaultErrorJson is a JSON representation of a simple error value, containing only a message and an error code.

type Endpoint

type Endpoint struct {
	Url  string
	Auth AuthorizationData
}

Endpoint is an endpoint with authorization data.

func HttpEndpoint

func HttpEndpoint(eth1Provider string) Endpoint

HttpEndpoint extracts an httputils.Endpoint from the provider parameter.

func (Endpoint) Equals

func (e Endpoint) Equals(other Endpoint) bool

Equals compares two endpoints for equality.

func (Endpoint) HttpClient

func (e Endpoint) HttpClient() *http.Client

HttpClient creates a http client object dependant on the properties of the network endpoint.

Directories

Path Synopsis
Package forks contains useful helpers for Ethereum consensus fork-related functionality.
Package forks contains useful helpers for Ethereum consensus fork-related functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL