node

package
v0.0.0-...-1c0411e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ReadSize = 1024

Variables

View Source
var (
	Request = packets.BasePacket[string]{
		Header: packets.PacketHeader{
			Flag: bootstrap.GET,
		},
		Payload: "",
	}
)

Functions

func Handler

func Handler(conn net.Conn, va ...interface{})

Handler reads from the connection conn and distributes the packets through the available handlers at handler.go

Types

type Flooder

type Flooder struct {
	Neighbours []netip.AddrPort
}

func NewFlooder

func NewFlooder(n []netip.AddrPort) Flooder

func (Flooder) Flood

func (f Flooder) Flood(packet packets.Packet, ignore ...netip.AddrPort) (packets.Packet, bool)

Flood sends a specialized message to each neighbour only taking into account the first answer to arrive, ignoring the others.

type Node

type Node struct {

	// information about what type of node I am, what are my neighbours
	Self bootstrap.Node

	// component responsible for flooding its neighbours with a packet
	Flooder Flooder

	// responsible for receiving tcp connections and handling them accordingly
	TCPHandler handlers.TCPConn

	// default address where the client listen to incoming requests
	Address netip.AddrPort

	// keeps track of handled requests
	Requests *RequestDb

	// relay pool, keeps track of receiving streams and who are we relaying them to
	RelayPool map[string]*Relay

	// positive, keeps track of received FOUND packets
	Positive map[uuid.UUID]string

	// each relay has a port
	CurrentPort uint64
	// contains filtered or unexported fields
}

func New

func New(bootstrapAddr string) *Node

New creates a new instance of a *Node.

func (*Node) AddRelay

func (n *Node) AddRelay(contentName string, relay *Relay) error

func (*Node) IsPositive

func (n *Node) IsPositive(requestId uuid.UUID) (string, bool)

func (*Node) IsStreaming

func (n *Node) IsStreaming(contentName string) bool

IsStreaming checks whether the current node is streaming a certain content by its contentName.

func (*Node) NextPort

func (n *Node) NextPort() uint64

func (*Node) OnDiscovery

func (n *Node) OnDiscovery(incoming packets.Packet, conn net.Conn)

func (*Node) OnStream

func (n *Node) OnStream(incoming packets.Packet, conn net.Conn)

func (*Node) Run

func (n *Node) Run()

Run starts the main listening loop and passes each connection to Handler.

func (*Node) SetPositive

func (n *Node) SetPositive(requestId uuid.UUID, source string)

SetPositive registers that we received a FOUND packet for the request with requestId and came from source. Only the first to come is registered.

type Relay

type Relay struct {
	// Name of the video that we are listening to from Origin.
	ContentName string
	// Address of which the video stream is coming from.
	Origin string

	// Slice containing the addresses (as *UDPAddr) to forward the bytes to.
	Addresses []*net.UDPAddr // no longer needed as for Connections
	// Default port for forwarding addresses.
	Port string

	Connections []*net.UDPConn
	// contains filtered or unexported fields
}

func NewRelay

func NewRelay(contentName string, origin string, port string) *Relay

NewRelay creates a new Relay object.

func (*Relay) Add

func (r *Relay) Add(address string) error

Add adds a new address into the Relay, this makes so that the bytes read from Loop are forwarder to address as well.

func (*Relay) Loop

func (r *Relay) Loop()

Loop reads a UDP stream from Origin and forwards it to the addresses specified in Addresses.

func (*Relay) Stop

func (r *Relay) Stop() error

Stop stops the reading from Origin by closing the connection.

type RequestDb

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

func NewRequestDb

func NewRequestDb() *RequestDb

func (*RequestDb) IsHandled

func (r *RequestDb) IsHandled(id uuid.UUID) bool

func (*RequestDb) Set

func (r *RequestDb) Set(id uuid.UUID, state bool)

Jump to

Keyboard shortcuts

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