actors

package
v0.0.0-...-0db62fc Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 24 Imported by: 0

README

TMan (Traffic Manager) contains logic that will try to holepunch NATs periodically if it detects that a connection is being used.

The Mermaid State Diagram under peer_state/peer_state.mermaid outlines this internal process.

The actors.mermaid diagram outlines the interactions between different actors.

Documentation

Index

Constants

View Source
const (
	EManTickerInterval = time.Second * 60

	EManStunTimeout = time.Second * 10
)
View Source
const (
	RelayConnectionRetryInterval = time.Second * 5

	RelayConnectionIdleAfter  = time.Minute * 1
	RelayConnectionBufferSize = 32
)
View Source
const (
	RMInboxLen   = 4
	RMInChLen    = 8
	RMWriteChLen = 8
)
View Source
const (
	SockRecvReadTimeout  = 5 * time.Second
	ConnActivityInterval = 10 * time.Second

	OutConnInboxChanBuffer = 10

	SockRecvFrameChanBuffer = 10
	InConnFrameChanBuffer   = 10

	// DefaultSafeMTU is a small MTU that'S safe, absent other information.
	DefaultSafeMTU uint16 = 1280
)
View Source
const DMChanWriteRequestLen = 4
View Source
const DRFrameChLen = 4
View Source
const DRInboxLen = 4
View Source
const RRFrameChLen = 4
View Source
const SMInboxLen = 8
View Source
const TManInboxLen = 16
View Source
const TManTickerInterval = time.Second

Variables

View Source
var DebugSManTakeNodeAsSession = false

Functions

func L

func L(a ifaces.Actor) *slog.Logger

func MakeStage

func MakeStage(
	pCtx context.Context,

	nodePriv func() *key.NodePrivate,
	sessPriv func() *key.SessionPrivate,

	bindExt func() types.UDPConn,
	bindLocal func(peer key.NodePublic) types.UDPConn,
	controlSession ifaces.ControlInterface,
) ifaces.Stage

func SendMessage

func SendMessage(ch chan<- msgactor.ActorMessage, msg msgactor.ActorMessage)

SendMessage is a convenience function to allow for "go SendMessage()"

Types

type ActorCommon

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

func MakeCommon

func MakeCommon(pCtx context.Context, chLen int) *ActorCommon

func (*ActorCommon) Cancel

func (ac *ActorCommon) Cancel()

func (*ActorCommon) Inbox

func (ac *ActorCommon) Inbox() chan<- msgactor.ActorMessage

type DirectManager

type DirectManager struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*DirectManager) Close

func (dm *DirectManager) Close()

func (*DirectManager) Run

func (dm *DirectManager) Run()

func (*DirectManager) WriteTo

func (dm *DirectManager) WriteTo(pkt []byte, addr netip.AddrPort)

WriteTo queues a UDP write request to a certain addr-port pair.

Will be called by other actors.

If the Packet is larger than the current MTU, it will be broken up.

type DirectRouter

type DirectRouter struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*DirectRouter) Close

func (dr *DirectRouter) Close()

func (*DirectRouter) Push

func (dr *DirectRouter) Push(frame ifaces.DirectedPeerFrame)

func (*DirectRouter) Run

func (dr *DirectRouter) Run()

type EndpointManager

type EndpointManager struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*EndpointManager) Close

func (em *EndpointManager) Close()

func (*EndpointManager) Run

func (em *EndpointManager) Run()

type InConn

type InConn struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func MakeInConn

func MakeInConn(udp types.UDPConn, peer key.NodePublic, s *Stage) *InConn

func (*InConn) Bump

func (ic *InConn) Bump()

Bump the activity timer.

func (*InConn) Close

func (ic *InConn) Close()

func (*InConn) Ctx

func (ic *InConn) Ctx() context.Context

func (*InConn) ForwardPacket

func (ic *InConn) ForwardPacket(pkt []byte)

ForwardPacket does a non-blocking packet forward.

This prevents routers from blocking when the conn is shutting down, or if its blocked otherwise.

func (*InConn) Run

func (ic *InConn) Run()

func (*InConn) SendActivity

func (ic *InConn) SendActivity(isActive bool)

func (*InConn) UnBump

func (ic *InConn) UnBump()

UnBump is called when the activity timer fires in the main loop

type InConnActor

type InConnActor interface {
	ifaces.Actor

	Ctx() context.Context

	ForwardPacket(pkt []byte)
}

type OutConn

type OutConn struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func MakeOutConn

func MakeOutConn(udp types.UDPConn, peer key.NodePublic, homeRelay int64, s *Stage) *OutConn

func (*OutConn) Bump

func (oc *OutConn) Bump()

Bump the activity timer.

func (*OutConn) Close

func (oc *OutConn) Close()

func (*OutConn) Ctx

func (oc *OutConn) Ctx() context.Context

func (*OutConn) Inbox

func (oc *OutConn) Inbox() chan<- msgactor.ActorMessage

func (*OutConn) Run

func (oc *OutConn) Run()

func (*OutConn) SendActivity

func (oc *OutConn) SendActivity(isActive bool)

func (*OutConn) UnBump

func (oc *OutConn) UnBump()

UnBump is called when the activity timer fires in the main loop

type OutConnActor

type OutConnActor interface {
	ifaces.Actor

	Ctx() context.Context
}

type RecvFrame

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

type RelayConnActor

type RelayConnActor interface {
	ifaces.Actor

	Queue(pkt []byte, peer key.NodePublic)
	Update(info relay.Information)
	StayConnected(bool)
}

type RelayManager

type RelayManager struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*RelayManager) Close

func (rm *RelayManager) Close()

func (*RelayManager) Run

func (rm *RelayManager) Run()

func (*RelayManager) WriteTo

func (rm *RelayManager) WriteTo(pkt []byte, relay int64, dst key.NodePublic)

WriteTo queues a packet relay request to a relay ID, for a certain public key.

Will be called by other actors.

type RelayRouter

type RelayRouter struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*RelayRouter) Close

func (rr *RelayRouter) Close()

func (*RelayRouter) Push

func (rr *RelayRouter) Push(frame ifaces.RelayedPeerFrame)

func (*RelayRouter) Run

func (rr *RelayRouter) Run()

type RestartableRelayConn

type RestartableRelayConn struct {
	*ActorCommon
	// contains filtered or unexported fields
}

RestartableRelayConn is a Relay connection that will automatically reconnect, as long as there are pending packets.

func (*RestartableRelayConn) Close

func (c *RestartableRelayConn) Close()

func (*RestartableRelayConn) L

func (*RestartableRelayConn) Queue

func (c *RestartableRelayConn) Queue(pkt []byte, dst key.NodePublic)

Queue queues the pkt for dst in a non-blocking fashion

func (*RestartableRelayConn) Run

func (c *RestartableRelayConn) Run()

func (*RestartableRelayConn) StayConnected

func (c *RestartableRelayConn) StayConnected(stay bool)

func (*RestartableRelayConn) Update

func (c *RestartableRelayConn) Update(info relay.Information)

type RunCheck

type RunCheck struct {
	*atomic.Bool
}

RunCheck ensures that only one instance of the actor is running at all times.

func MakeRunCheck

func MakeRunCheck() RunCheck

func (*RunCheck) CheckOrMark

func (rc *RunCheck) CheckOrMark() bool

CheckOrMark atomically checks if its already running, else marks as running, returns a false value if the instance is already running.

type SessionManager

type SessionManager struct {
	*ActorCommon
	// contains filtered or unexported fields
}

SessionManager receives frames from routers and decrypts them, and forwards the resulting messages to the traffic manager.

It also receives messages from the traffic manager, encrypts them, and forwards them to the direct/relay managers.

func (*SessionManager) Close

func (sm *SessionManager) Close()

func (*SessionManager) Handle

func (sm *SessionManager) Handle(msg msgactor.ActorMessage)

func (*SessionManager) Pack

func (sm *SessionManager) Pack(sMsg msg2.SessionMessage, toSession key.SessionPublic) []byte

func (*SessionManager) Run

func (sm *SessionManager) Run()

func (*SessionManager) Session

func (sm *SessionManager) Session() key.SessionPublic

func (*SessionManager) Unpack

func (sm *SessionManager) Unpack(frameWithMagic []byte) (*msg2.ClearMessage, error)

type SockRecv

type SockRecv struct {
	*ActorCommon

	Conn types.UDPConn
	// contains filtered or unexported fields
}

func MakeSockRecv

func MakeSockRecv(udp types.UDPConn, pCtx context.Context) *SockRecv

func (*SockRecv) Close

func (r *SockRecv) Close()

func (*SockRecv) Run

func (r *SockRecv) Run()

type Stage

type Stage struct {
	// The parent context of the stage that all actors must parent
	Ctx context.Context

	// The DirectManager
	DMan ifaces.DirectManagerActor
	// The DirectRouter
	DRouter ifaces.DirectRouterActor

	// The RelayManager
	RMan ifaces.RelayManagerActor
	// The RelayRouter
	RRouter ifaces.RelayRouterActor

	// The TrafficManager
	TMan ifaces.TrafficManagerActor
	// The SessionManager
	SMan ifaces.SessionManagerActor
	// The EndpointManager
	EMan ifaces.EndpointManagerActor
	// contains filtered or unexported fields
}

Stage for the Actors

func (*Stage) AddPeer

func (s *Stage) AddPeer(peer key.NodePublic, homeRelay int64, endpoints []netip.AddrPort, session key.SessionPublic, _ netip.Addr, _ netip.Addr) error

func (*Stage) ControlSTUN

func (s *Stage) ControlSTUN() []netip.AddrPort

ControlSTUN returns a set of endpoints pertaining to Control's STUN addrpairs

func (*Stage) GetEndpoints

func (s *Stage) GetEndpoints() []netip.AddrPort

func (*Stage) GetPeerInfo

func (s *Stage) GetPeerInfo(peer key.NodePublic) *stage.PeerInfo

GetPeerInfo gets a copy of the peerinfo for peer

func (*Stage) InConnFor

func (s *Stage) InConnFor(peer key.NodePublic) InConnActor

InConnFor Looks up the InConn for a peer. Returns nil if it doesn't exist.

func (*Stage) OutConnFor

func (s *Stage) OutConnFor(peer key.NodePublic) OutConnActor

OutConnFor Looks up the OutConn for a peer. Returns nil if it doesn't exist.

func (*Stage) RemovePeer

func (s *Stage) RemovePeer(peer key.NodePublic) error

func (*Stage) SetEndpoints

func (s *Stage) SetEndpoints(peer key.NodePublic, endpoints []netip.AddrPort) error

SetEndpoints set the known public addresses for a particular peer.

func (*Stage) Start

func (s *Stage) Start()

Start kicks off goroutines for the stage and returns

func (*Stage) UpdateHomeRelay

func (s *Stage) UpdateHomeRelay(peer key.NodePublic, relay int64) error

func (*Stage) UpdatePeer

func (s *Stage) UpdatePeer(peer key.NodePublic, homeRelay *int64, endpoints []netip.AddrPort, session *key.SessionPublic) error

func (*Stage) UpdateRelays

func (s *Stage) UpdateRelays(relays []relay.Information) error

func (*Stage) UpdateSessionKey

func (s *Stage) UpdateSessionKey(peer key.NodePublic, session key.SessionPublic) error

UpdateSessionKey updates the known session key for a particular peer.

func (*Stage) Watchdog

func (s *Stage) Watchdog()

Watchdog will be run to constantly check for faults on the stage and repair them.

type StateForState

type StateForState func(state peer_state.PeerState) peer_state.PeerState

type TrafficManager

type TrafficManager struct {
	*ActorCommon
	// contains filtered or unexported fields
}

func (*TrafficManager) ActiveIn

func (tm *TrafficManager) ActiveIn() map[key.NodePublic]bool

func (*TrafficManager) ActiveOut

func (tm *TrafficManager) ActiveOut() map[key.NodePublic]bool

func (*TrafficManager) Close

func (tm *TrafficManager) Close()

func (*TrafficManager) DManClearAKA

func (tm *TrafficManager) DManClearAKA(peer key.NodePublic)

func (*TrafficManager) DManSetAKA

func (tm *TrafficManager) DManSetAKA(peer key.NodePublic, ap netip.AddrPort)

func (*TrafficManager) DoStateTick

func (tm *TrafficManager) DoStateTick()

func (*TrafficManager) Handle

func (tm *TrafficManager) Handle(m msgactor.ActorMessage)

func (*TrafficManager) NodeForSess

func (tm *TrafficManager) NodeForSess(sess key.SessionPublic) *key.NodePublic

func (*TrafficManager) OutConnTrackHome

func (tm *TrafficManager) OutConnTrackHome(peer key.NodePublic)

func (*TrafficManager) OutConnUseAddrPort

func (tm *TrafficManager) OutConnUseAddrPort(peer key.NodePublic, ap netip.AddrPort)

func (*TrafficManager) OutConnUseRelay

func (tm *TrafficManager) OutConnUseRelay(peer key.NodePublic, relay int64)

func (*TrafficManager) Pings

func (tm *TrafficManager) Pings() map[msgsess.TxID]*stage.SentPing

func (*TrafficManager) Poke

func (tm *TrafficManager) Poke()

Poke is a convenience method to have TMan poke OnTick for states ASAP (after message queues get cleared).

func (*TrafficManager) Run

func (tm *TrafficManager) Run()

func (*TrafficManager) SendMsgToDirect

func (tm *TrafficManager) SendMsgToDirect(ap netip.AddrPort, sess key.SessionPublic, m msgsess.SessionMessage)

func (*TrafficManager) SendMsgToRelay

func (tm *TrafficManager) SendMsgToRelay(relay int64, peer key.NodePublic, sess key.SessionPublic, m msgsess.SessionMessage)

func (*TrafficManager) SendPingDirect

func (tm *TrafficManager) SendPingDirect(endpoint netip.AddrPort, peer key.NodePublic, session key.SessionPublic)

func (*TrafficManager) SendPingRelay

func (tm *TrafficManager) SendPingRelay(relay int64, peer key.NodePublic, session key.SessionPublic)

func (*TrafficManager) Stage

func (tm *TrafficManager) Stage() ifaces.Stage

func (*TrafficManager) ValidKeys

func (tm *TrafficManager) ValidKeys(peer key.NodePublic, session key.SessionPublic) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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