proxy

package
v0.0.0-...-cdc5ecf Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ProxyProtocolID = protocol.ID("/bethrou/proxy/1.0.0")
	PingProtocolID  = protocol.ID("/bethrou/ping/1.0.0")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host host.Host
	Pool *Pool
}

Client is the client-side proxy dialer that connects to exit nodes

func NewClient

func NewClient(h host.Host, p *Pool) *Client

NewClient creates a new client-side proxy dialer

func (*Client) Connect

func (p *Client) Connect(ctx context.Context, nodes []config.NodeConfig) error

func (*Client) Dial

func (d *Client) Dial(ctx context.Context, peerID peer.ID, addr string) (net.Conn, error)

Dial establishes a proxy connection through a specific exit node

func (*Client) DialByStrategy

func (d *Client) DialByStrategy(ctx context.Context, addr string) (net.Conn, error)

DialByStrategy dials an exit node based on the pool's current strategy.

func (*Client) DialFastest

func (d *Client) DialFastest(ctx context.Context, addr string) (net.Conn, error)

func (*Client) DialRandom

func (d *Client) DialRandom(ctx context.Context, addr string) (net.Conn, error)

func (*Client) DialRoundRobin

func (d *Client) DialRoundRobin(ctx context.Context, addr string) (net.Conn, error)

func (*Client) Ping

func (d *Client) Ping(ctx context.Context, conn *Connection) (time.Duration, error)

Ping checks the latency to a proxy node by opening and closing a stream

type Connection

type Connection struct {
	PeerID  peer.ID
	Addr    string
	Latency time.Duration
}

Connection represents a connection to a proxy node

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(strategy PoolStrategy) *Pool

func (*Pool) Add

func (p *Pool) Add(peerID peer.ID, addr string)

func (*Pool) All

func (p *Pool) All() []*Connection

func (*Pool) Clear

func (p *Pool) Clear()

func (*Pool) GetStrategy

func (p *Pool) GetStrategy() PoolStrategy

func (*Pool) Remove

func (p *Pool) Remove(peerID peer.ID)

func (*Pool) SelectByStrategy

func (p *Pool) SelectByStrategy(strategy PoolStrategy) *Connection

func (*Pool) SelectFastest

func (p *Pool) SelectFastest() *Connection

func (*Pool) SelectRandom

func (p *Pool) SelectRandom() *Connection

func (*Pool) SelectRoundRobin

func (p *Pool) SelectRoundRobin() *Connection

func (*Pool) SetStrategy

func (p *Pool) SetStrategy(s PoolStrategy)

func (*Pool) Size

func (p *Pool) Size() int

func (*Pool) UpdateLatency

func (p *Pool) UpdateLatency(peerID peer.ID, latency time.Duration)

type PoolStrategy

type PoolStrategy string
const (
	RandomStrategy     PoolStrategy = "random"
	FastestStrategy    PoolStrategy = "latency"
	RoundRobinStrategy PoolStrategy = "round-robin"
)

type ProxyResponse

type ProxyResponse struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
}

type Request

type Request struct {
	ProxyAddress string `json:"address"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles incoming proxy requests from clients

func NewServer

func NewServer(h host.Host) *Server

NewServer creates a new proxy handler for the server (node) side

func (*Server) Listen

func (s *Server) Listen(ctx context.Context)

Jump to

Keyboard shortcuts

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