aw

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 18 Imported by: 0

README

🌪 airwave

GoDoc Go Report Coverage Status

A flexible P2P networking library for upgradable distributed systems. The core mission of airwave is to provide a simple P2P interface that can support a wide variety of different algorithms, with a focus on backwards compatible. The P2P interface supports:

  • Peer discovery
  • Handshake
  • Casting (send to one)
  • Multicasting (send to many)
  • Broadcasting (send to everyone)
Handshake

Airwave uses a 3 way sync handshake method to authorize peers in the network. The process is as follows:

The client sends a signed rsa public key on connect. The server validates the signature, generates a random challenge, and sends the signed random challenge encrypted with the client's public key; and the server's public key. The client validates the server's signature decrypts the challenge encrypts it with the server's publickey, signs it and sends it back.

Built with ❤ by Ren.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSubnet = id.Hash{
		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	}

	DefaultMaxLinkedPeers               uint          = 100
	DefaultMaxEphemeralConnections      uint          = 20
	DefaultMaxPendingSyncs              uint          = 100
	DefaultMaxActiveSyncsForSameContent uint          = 10
	DefaultMaxGossipSubnets             uint          = 100 // ?
	DefaultMaxMessageSize               uint          = 1024
	DefaultOutgoingBufferSize           uint          = 100
	DefaultEventLoopBufferSize          uint          = 100
	DefaultOutgoingBufferTimeout        time.Duration = time.Second
	DefaultWriteTimeout                 time.Duration = time.Second
	DefaultDialRetryInterval            time.Duration = time.Second
	DefaultEphemeralConnectionTTL       time.Duration = 5 * time.Second
	DefaultMinimumConnectionExpiryAge   time.Duration = time.Minute
	DefaultGossipAlpha                  int           = 5
	DefaultGossipTimeout                time.Duration = 5 * time.Second // ?
	DefaultPingAlpha                    int           = 5
	DefaultPongAlpha                    int           = 10
	DefaultPeerDiscoveryInterval        time.Duration = 30 * time.Second
	DefaultPeerExpiryTimeout            time.Duration = 30 * time.Second
)
View Source
var (
	ErrTooManyLinkedPeers          = errors.New("too many linked peers")
	ErrTooManyEphemeralConnections = errors.New("too many ephemeral connections")
	ErrMessageBufferFull           = errors.New("outgoing message buffer is full")
	ErrEventLoopFull               = errors.New("event loop buffer is full")
	ErrTooManyPendingSyncs         = errors.New("too many pending sync requests")
	ErrTooManySyncsForSameContent  = errors.New("too many simultaneous syncs for the same content ID")
)
View Source
var (
	DefaultRateLimiterCapacity        int                = 10
	DefaultListenerRateLimiterOptions RateLimiterOptions = RateLimiterOptions{Rate: 10, Burst: 20}
	DefaultRate                       rate.Limit         = 1024 * 1024
	DefaultBurst                      int                = 4 * 1024 * 1024
)

Functions

This section is empty.

Types

type ListenerOptions added in v0.6.0

type ListenerOptions struct {
	RateLimiterCapacity int
	RateLimiterOptions
}

func DefaultListenerOptions added in v0.6.0

func DefaultListenerOptions() ListenerOptions

type Options added in v0.4.0

type Options struct {
	Logger *zap.Logger

	MaxLinkedPeers               uint
	MaxEphemeralConnections      uint
	MaxPendingSyncs              uint
	MaxActiveSyncsForSameContent uint
	MaxGossipSubnets             uint
	MaxMessageSize               uint
	OutgoingBufferSize           uint
	EventLoopBufferSize          uint
	OutgoingBufferTimeout        time.Duration
	WriteTimeout                 time.Duration
	DialRetryInterval            time.Duration
	EphemeralConnectionTTL       time.Duration
	MinimumConnectionExpiryAge   time.Duration

	GossipAlpha   int
	GossipTimeout time.Duration

	PingAlpha             int
	PongAlpha             int
	PeerDiscoveryInterval time.Duration
	PeerExpiryTimeout     time.Duration

	ListenerOptions              ListenerOptions
	ConnectionRateLimiterOptions RateLimiterOptions
}

func DefaultOptions added in v0.4.0

func DefaultOptions() Options

type Peer

type Peer struct {
	Opts Options

	Port uint16

	PeerTable       dht.Table
	ContentResolver dht.ContentResolver
	// contains filtered or unexported fields
}

func New

func New(opts Options, privKey *id.PrivKey, peerTable dht.Table, contentResolver dht.ContentResolver, receive func(id.Signatory, []byte)) *Peer

func (*Peer) Gossip added in v0.6.0

func (peer *Peer) Gossip(ctx context.Context, contentID []byte, subnet *id.Hash) error

func (*Peer) GossipNonBlocking added in v0.6.0

func (peer *Peer) GossipNonBlocking(contentID []byte, subnet *id.Hash) error

func (*Peer) ID added in v0.6.0

func (peer *Peer) ID() id.Signatory
func (peer *Peer) Link(remote id.Signatory) error

func (*Peer) Listen added in v0.6.0

func (peer *Peer) Listen(ctx context.Context, address string) (uint16, error)

func (*Peer) Receive added in v0.6.0

func (peer *Peer) Receive(receive func(id.Signatory, []byte))

func (*Peer) Run

func (peer *Peer) Run(ctx context.Context) error

func (*Peer) Send added in v0.6.0

func (peer *Peer) Send(ctx context.Context, data []byte, remote id.Signatory) error

func (*Peer) SendNonBlocking added in v0.6.0

func (peer *Peer) SendNonBlocking(data []byte, remote id.Signatory) error

func (*Peer) Sync added in v0.6.0

func (peer *Peer) Sync(ctx context.Context, contentID []byte, hint *id.Signatory) ([]byte, error)

func (*Peer) SyncNonBlocking added in v0.6.0

func (peer *Peer) SyncNonBlocking(ctx context.Context, contentID []byte, hint *id.Signatory) ([]byte, error)
func (peer *Peer) Unlink(remote id.Signatory) error

type RateLimiterOptions added in v0.6.0

type RateLimiterOptions struct {
	Rate  rate.Limit
	Burst int
}

func DefaultRateLimiterOptions added in v0.6.0

func DefaultRateLimiterOptions() RateLimiterOptions

Directories

Path Synopsis
dht

Jump to

Keyboard shortcuts

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