network

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 30 Imported by: 1

Documentation

Overview

Package network implements utilities for dialing and listening to secret-handshake powered muxrpc connections.

Index

Constants

View Source
const DefaultPort = 8008

DefaultPort is the default listening port for ScuttleButt.

Variables

This section is empty.

Functions

func NewAcceptAllTracker

func NewAcceptAllTracker() ssb.ConnTracker

This just keeps a count and doesn't actually track anything

func NewConnTracker

func NewConnTracker() ssb.ConnTracker

func NewInstrumentedConnTracker

func NewInstrumentedConnTracker(r ssb.ConnTracker, ct metrics.Gauge, h metrics.Histogram) ssb.ConnTracker

func NewLastWinsTracker

func NewLastWinsTracker() ssb.ConnTracker

NewLastWinsTracker returns a conntracker that just kills the previous connection and let's the new one in.

Types

type Advertiser

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

func NewAdvertiser

func NewAdvertiser(local net.Addr, keyPair ssb.KeyPair) (*Advertiser, error)

func (*Advertiser) Start

func (b *Advertiser) Start()

func (*Advertiser) Stop

func (b *Advertiser) Stop()

type Discoverer

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

func NewDiscoverer

func NewDiscoverer(local ssb.KeyPair) (*Discoverer, error)

func (*Discoverer) Notify

func (d *Discoverer) Notify() (<-chan net.Addr, func())

func (*Discoverer) Stop

func (d *Discoverer) Stop()

type Node added in v0.2.1

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

func New

func New(opts Options) (*Node, error)

func (*Node) Close added in v0.2.1

func (n *Node) Close() error

func (*Node) Connect added in v0.2.1

func (n *Node) Connect(ctx context.Context, addr net.Addr) error

func (*Node) DialViaRoom added in v0.2.1

func (n *Node) DialViaRoom(portal, target refs.FeedRef) error

func (*Node) GetAllEndpoints added in v0.2.1

func (n *Node) GetAllEndpoints() []ssb.EndpointStat

TODO: merge with conntracker

func (*Node) GetConnTracker added in v0.2.1

func (n *Node) GetConnTracker() ssb.ConnTracker

func (*Node) GetEndpointFor added in v0.2.1

func (n *Node) GetEndpointFor(ref refs.FeedRef) (muxrpc.Endpoint, bool)

GetEndpointFor returns a muxrpc endpoint to call the remote identified by the passed feed ref retruns false if there is no such connection TODO: merge with conntracker

func (*Node) GetListenAddr added in v0.2.1

func (n *Node) GetListenAddr() net.Addr

GetListenAddr waits for Serve() to be called!

func (*Node) HandleHTTP added in v0.2.1

func (n *Node) HandleHTTP(h http.Handler)

func (*Node) Serve added in v0.2.1

func (n *Node) Serve(ctx context.Context, wrappers ...muxrpc.HandlerWrapper) error

Serve starts the network listener and configured resources like local discovery. Canceling the passed context makes the function return. Defers take care of stopping these resources.

func (*Node) TunnelPlugin added in v0.2.1

func (n *Node) TunnelPlugin() ssb.Plugin

TunnelPlugin returns a muxrpc plugin that is able to handle incoming tunnel.connect requests

type Options

type Options struct {
	Logger log.Logger

	Dialer     netwrap.Dialer
	ListenAddr net.Addr

	AdvertsSend      bool
	AdvertsConnectTo bool

	KeyPair     ssb.KeyPair
	AppKey      []byte
	MakeHandler func(net.Conn) (muxrpc.Handler, error)

	ConnTracker ssb.ConnTracker

	// PreSecureWrappers are applied before the shs+boxstream wrapping takes place
	// usefull for accessing the sycall.Conn to apply control options on the socket
	BefreCryptoWrappers []netwrap.ConnWrapper

	// AfterSecureWrappers are applied afterwards, usefull to debug muxrpc content
	AfterSecureWrappers []netwrap.ConnWrapper

	EventCounter    metrics.Counter
	SystemGauge     metrics.Gauge
	Latency         metrics.Histogram
	EndpointWrapper func(muxrpc.Endpoint) muxrpc.Endpoint

	WebsocketAddr string
}

Jump to

Keyboard shortcuts

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