network

package
v0.0.0-...-5292a0b Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTLS

func GenerateTLS() (string, string, error)

GenerateTLS generates a TLS certificate and private key

Types

type Config

type Config struct {
	// Port is the port to listen on
	Port int

	// Timeout is the timeout for connections
	Timeout time.Duration

	// TLS is the TLS configuration
	TLS TLSConfig
}

Config represents the configuration for the network

type Network

type Network struct {
	// Config is the configuration for the network
	Config Config

	// Peers is a list of peers in the network
	Peers []Peer

	// Mutex is a mutex to protect access to the peers
	Mutex sync.RWMutex

	// Listener is the listener for incoming connections
	Listener net.Listener

	// Dialer is the dialer for outgoing connections
	Dialer net.Dialer
}

Network represents a network

func NewNetwork

func NewNetwork(config Config) *Network

NewNetwork returns a new network

func (*Network) Dial

func (n *Network) Dial(peer Peer) (net.Conn, error)

Dial dials a peer

func (*Network) MarshalJSON

func (n *Network) MarshalJSON() ([]byte, error)

MarshalJSON marshals the network to JSON

func (*Network) Start

func (n *Network) Start() error

Start starts the network

func (*Network) UnmarshalJSON

func (n *Network) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON to the network

type Peer

type Peer struct {
	// ID is the ID of the peer
	ID string

	// Address is the address of the peer
	Address string

	// Conn is the connection to the peer
	Conn net.Conn
}

Peer represents a peer in the network

type TLSConfig

type TLSConfig struct {
	// Cert is the TLS certificate
	Cert string

	// Key is the TLS private key
	Key string
}

TLSConfig represents the TLS configuration

Jump to

Keyboard shortcuts

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