and

package
v0.1.202602121754 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

and (Abyss Neighbor Discovery) algorithm defines worlds in abyss network. A World is created by OpenWorld or JoinWorld call on AND, which is the algorithm provider. Calling world writes back events synchronously. World algorithm may request a peer through event. On host-side event consumer prvides peer (by dialing or just giving connected peer). When a peer closes, the host calls PeerClose() to each world that references the peer. By this way, the host has full control over peer references.

Index

Constants

View Source
const (
	JNC_REDUNDANT = 110

	//Joiner-side problem
	JNC_NOT_FOUND = 404
	JNC_DUPLICATE = 480
	JNC_OVERRUN   = 481
	JNC_CANCELED  = 498
	JNC_CLOSED    = 499

	//Accepter-side response
	JNC_COLLISION = 520
	JNC_EXPIRED   = 530
	JNC_REJECTED  = 599

	//Non-Joining state
	JNC_UNEXPECTED_WSID = 600
	JNC_INVALID_STATES  = 610

	//Network issue
	JNC_DISCONNECTED = 700
)
View Source
const (
	JNM_REDUNDANT = "Already Joined"

	JNM_NOT_FOUND = "Not Found"
	JNM_DUPLICATE = "Duplicate Join"
	JNM_OVERRUN   = "World Session Overrun"
	JNM_CANCELED  = "Join Canceled"
	JNM_CLOSED    = "Peer Disconnected"

	JNM_COLLISION = "Session ID Collided"
	JNM_EXPIRED   = "Join Expired"
	JNM_REJECTED  = "Join Rejected"

	JNM_UNEXPECTED_WSID = "Unexpected Session ID"
	JNM_INVALID_STATES  = "Invalid States"

	JNM_DISCONNECTED = "Disconnected"
)
View Source
const INITIAL_WORLD_TIMER = 1000

Variables

This section is empty.

Functions

func SendJDN_NoWorld added in v0.1.202602121754

func SendJDN_NoWorld(peer_session ANDPeerSession, code int, message string) error

func SendRST_UnexpectedArbitraryWorld added in v0.1.202602121754

func SendRST_UnexpectedArbitraryWorld(peer_session ANDPeerSession, unknown_wsid uuid.UUID) error

Types

type AND

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

func NewAND

func NewAND(local_id string) *AND

func (*AND) JoinWorld

func (a *AND) JoinWorld(target ani.IAbyssPeer, path string) (*World, error)

func (*AND) OpenWorld

func (a *AND) OpenWorld(events ds.Queue, world_url string) *World

type ANDFullPeerSessionInfo added in v0.1.202602121754

type ANDFullPeerSessionInfo struct {
	PeerID                     string
	AddressCandidates          []netip.AddrPort
	SessionID                  uuid.UUID
	TimeStamp                  time.Time
	RootCertificateDer         []byte
	HandshakeKeyCertificateDer []byte
}

ANDFullPeerSessionInfo provides all the information required to connect a peer, identify its world session, negotiate ordering. As a result, a peer who receives this can construct ANDFullPeerSession.

type ANDPeerSession added in v0.1.202602121754

type ANDPeerSession struct {
	Peer      ani.IAbyssPeer
	SessionID uuid.UUID
}

ANDPeerSession is used to indirect a peer world session in IANDEvent.

type ANDPeerSessionIdentity added in v0.1.202602121754

type ANDPeerSessionIdentity struct {
	PeerID    string
	SessionID uuid.UUID
}

ANDPeerSessionIdentity is used to indirect a peer world session, which is used in connection recovery.

type ANDSessionState added in v0.1.202602121754

type ANDSessionState int
const (
	// WS_DC_JNI : disconnected, JNI received
	// (X) Peer, is_session_requested
	// (O) PeerID, SessionID, TimeStamp
	WS_DC_JNI ANDSessionState = iota + 1

	// WS_CC : connected, no info. <<W_Joining>>
	// (X) SessionID, TimeStamp, is_session_requested
	WS_CC

	// WS_JN : JN received
	// (O) SessionID, TimeStamp, is_session_requested
	WS_JN

	// WS_RMEM_NJNI : MEM received, JNI not received. <<W_Joining>>
	// (X) is_session_requested
	// (O) SessionID, TimeStamp
	WS_RMEM_NJNI

	// WS_JNI : JNI received, MEM not received
	// (X)
	// (O) SessionID, TimeStamp is_session_requested
	WS_JNI

	// WS_RMEM : MEM received
	// (X)
	// (O) SessionID, TimeStamp, is_session_requested
	WS_RMEM

	// WS_TMEM : MEM/JOK sent
	// (X)
	// (O) SessionID, TimeStamp, is_session_requested
	WS_TMEM

	// WS_MEM : member
	// (X)
	// (O) SessionID, TimeStamp, is_session_requested
	WS_MEM
)

func (ANDSessionState) String added in v0.1.202602121754

func (s ANDSessionState) String() string

type ANDStatistics

type ANDStatistics struct {
	JN_TX  int
	JOK_TX int
	JDN_TX int
	JNI_TX int
	MEM_TX int
	SJN_TX int
	CRR_TX int
	RST_TX int
	SOA_TX int
	SOD_TX int

	JN_RX  int
	JOK_RX int
	JDN_RX int
	JNI_RX int
	MEM_RX int
	SJN_RX int
	CRR_RX int
	RST_RX int
	SOA_RX int
	SOD_RX int
}

func (*ANDStatistics) B

func (s *ANDStatistics) B(i int)

func (*ANDStatistics) String

func (s *ANDStatistics) String() string

func (*ANDStatistics) W

func (s *ANDStatistics) W(i int)

type CRR added in v0.1.202602121754

type CRR struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	MemberInfos     []ANDPeerSessionIdentity
}

type EANDError added in v0.1.202602121754

type EANDError struct {
}

type EANDObjectAppend added in v0.1.202602121754

type EANDObjectAppend struct {
	World *World
	ANDPeerSession
	Objects []ObjectInfo
}

type EANDObjectDelete added in v0.1.202602121754

type EANDObjectDelete struct {
	World *World
	ANDPeerSession
	ObjectIDs []uuid.UUID
}

type EANDPeerDiscard added in v0.1.202602121754

type EANDPeerDiscard struct {
	World *World
	Peer  ani.IAbyssPeer
}

type EANDPeerRequest added in v0.1.202602121754

type EANDPeerRequest struct {
	World                      *World
	PeerID                     string
	AddressCandidates          []netip.AddrPort
	RootCertificateDer         []byte
	HandshakeKeyCertificateDer []byte
}

type EANDSessionClose added in v0.1.202602121754

type EANDSessionClose struct {
	World *World
	ANDPeerSession
}

type EANDSessionReady added in v0.1.202602121754

type EANDSessionReady struct {
	World *World
	ANDPeerSession
}

type EANDSessionRequest added in v0.1.202602121754

type EANDSessionRequest struct {
	World *World
	ANDPeerSession
}

type EANDTimerRequest added in v0.1.202602121754

type EANDTimerRequest struct {
	World    *World
	Duration time.Duration
}

type EANDWorldEnter added in v0.1.202602121754

type EANDWorldEnter struct {
	World *World
	URL   string
}

type EANDWorldLeave added in v0.1.202602121754

type EANDWorldLeave struct {
	World   *World
	Code    int
	Message string
}

type IANDEvent added in v0.1.202602121754

type IANDEvent any

IANDEvent conveys event/request from AND to host. a session may close before ready, but never before request. No event should be pushed after JoinFail or WorldLeave. This must be a pointer for an EAND struct.

type INVAL added in v0.1.202602121754

type INVAL struct {
	Err error
}

type JDN added in v0.1.202602121754

type JDN struct {
	RecverSessionID uuid.UUID
	Code            int
	Message         string
}

type JN added in v0.1.202602121754

type JN struct {
	SenderSessionID uuid.UUID
	Path            string
	TimeStamp       time.Time
}

type JNI added in v0.1.202602121754

type JNI struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	Neighbor        ANDFullPeerSessionInfo
}

type JOK added in v0.1.202602121754

type JOK struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	URL             string
	TimeStamp       time.Time
	Neighbors       []ANDFullPeerSessionInfo
}

type MEM added in v0.1.202602121754

type MEM struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	TimeStamp       time.Time
}

type ObjectInfo added in v0.1.202602121754

type ObjectInfo struct {
	ID        uuid.UUID
	Addr      string
	Transform [7]float32
}

ObjectInfo is used to represent shared object.

type RST added in v0.1.202602121754

type RST struct {
	SenderSessionID uuid.UUID //may nil.
	RecverSessionID uuid.UUID
	Code            int
	Message         string //optional
}

type RawCRR added in v0.1.202602121754

type RawCRR struct {
	SenderSessionID string
	RecverSessionID string
	MemberInfos     []RawSessionInfoForSJN
}

func (*RawCRR) TryParse added in v0.1.202602121754

func (r *RawCRR) TryParse() (*CRR, error)

type RawJDN added in v0.1.202602121754

type RawJDN struct {
	RecverSessionID string
	Code            int
	Message         string
}

func (*RawJDN) TryParse added in v0.1.202602121754

func (r *RawJDN) TryParse() (*JDN, error)

type RawJN added in v0.1.202602121754

type RawJN struct {
	SenderSessionID string
	Path            string
	TimeStamp       int64
}

func (*RawJN) TryParse added in v0.1.202602121754

func (r *RawJN) TryParse() (*JN, error)

type RawJNI added in v0.1.202602121754

type RawJNI struct {
	SenderSessionID string
	RecverSessionID string
	Joiner          RawSessionInfoForDiscovery
}

func (*RawJNI) TryParse added in v0.1.202602121754

func (r *RawJNI) TryParse() (*JNI, error)

type RawJOK added in v0.1.202602121754

type RawJOK struct {
	SenderSessionID string
	RecverSessionID string
	URL             string
	TimeStamp       int64
	Neighbors       []RawSessionInfoForDiscovery
}

func (*RawJOK) TryParse added in v0.1.202602121754

func (r *RawJOK) TryParse() (*JOK, error)

type RawMEM added in v0.1.202602121754

type RawMEM struct {
	SenderSessionID string
	RecverSessionID string
	TimeStamp       int64
}

func (*RawMEM) TryParse added in v0.1.202602121754

func (r *RawMEM) TryParse() (*MEM, error)

type RawObjectInfo added in v0.1.202602121754

type RawObjectInfo struct {
	ID        string
	Address   string
	Transform [7]float32
}

type RawRST added in v0.1.202602121754

type RawRST struct {
	SenderSessionID string
	RecverSessionID string
	Code            int
	Message         string
}

func (*RawRST) TryParse added in v0.1.202602121754

func (r *RawRST) TryParse() (*RST, error)

type RawSJN added in v0.1.202602121754

type RawSJN struct {
	SenderSessionID string
	RecverSessionID string
	MemberInfos     []RawSessionInfoForSJN
}

func (*RawSJN) TryParse added in v0.1.202602121754

func (r *RawSJN) TryParse() (*SJN, error)

type RawSOA added in v0.1.202602121754

type RawSOA struct {
	SenderSessionID string
	RecverSessionID string
	Objects         []RawObjectInfo
}

func (*RawSOA) TryParse added in v0.1.202602121754

func (r *RawSOA) TryParse() (*SOA, error)

type RawSOD added in v0.1.202602121754

type RawSOD struct {
	SenderSessionID string
	RecverSessionID string
	ObjectIDs       []string
}

func (*RawSOD) TryParse added in v0.1.202602121754

func (r *RawSOD) TryParse() (*SOD, error)

type RawSessionInfoForDiscovery added in v0.1.202602121754

type RawSessionInfoForDiscovery struct {
	PeerID                     string
	AddressCandidates          []string
	SessionID                  string
	TimeStamp                  int64
	RootCertificateDer         []byte
	HandshakeKeyCertificateDer []byte
}

func MakeRawSessionInfoForDiscovery added in v0.1.202602121754

func MakeRawSessionInfoForDiscovery(entry *peerWorldSessionState) RawSessionInfoForDiscovery

type RawSessionInfoForSJN added in v0.1.202602121754

type RawSessionInfoForSJN struct {
	PeerID    string
	SessionID string
}

func MakeRawSessionInfoForSJN added in v0.1.202602121754

func MakeRawSessionInfoForSJN(entry *peerWorldSessionState) RawSessionInfoForSJN

type SJN added in v0.1.202602121754

type SJN struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	MemberInfos     []ANDPeerSessionIdentity
}

type SOA added in v0.1.202602121754

type SOA struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	Objects         []ObjectInfo
}

type SOD added in v0.1.202602121754

type SOD struct {
	SenderSessionID uuid.UUID
	RecverSessionID uuid.UUID
	ObjectIDs       []uuid.UUID
}

type World added in v0.1.202602121754

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

World is a state machine for a world and its member/related peers. Removing join target from a world breakes it, so be careful. A world must be externally locked, using the embedded sync.Mutex. This gives better control over call and event synchronization for the host.

func (*World) AcceptSession added in v0.1.202602121754

func (w *World) AcceptSession(events ds.Queue, peer_session_identity ANDPeerSessionIdentity)

func (*World) CRR added in v0.1.202602121754

func (w *World) CRR(events ds.Queue, peer_session ANDPeerSession, member_infos []ANDPeerSessionIdentity)

func (*World) CheckSanity added in v0.1.202602121754

func (w *World) CheckSanity()

func (*World) Close added in v0.1.202602121754

func (w *World) Close()

Close does not take events argument, as the world is closed immediately. no events are meaningful afterwards.

func (*World) DeclineSession added in v0.1.202602121754

func (w *World) DeclineSession(events ds.Queue, peer_session_identity ANDPeerSessionIdentity, code int, message string)

func (*World) IsExposable added in v0.1.202602121754

func (w *World) IsExposable() bool

IsExposable checks if the world joining procedure is finished and the world information is set.

func (*World) JDN added in v0.1.202602121754

func (w *World) JDN(events ds.Queue, peer ani.IAbyssPeer, code int, message string)

func (*World) JN added in v0.1.202602121754

func (w *World) JN(events ds.Queue, peer_session ANDPeerSession, timestamp time.Time)

func (*World) JNI added in v0.1.202602121754

func (w *World) JNI(events ds.Queue, peer_session ANDPeerSession, member_info ANDFullPeerSessionInfo)

func (*World) JOK added in v0.1.202602121754

func (w *World) JOK(events ds.Queue, peer_session ANDPeerSession, timestamp time.Time, world_url string, member_infos []ANDFullPeerSessionInfo)

func (*World) MEM added in v0.1.202602121754

func (w *World) MEM(events ds.Queue, peer_session ANDPeerSession, timestamp time.Time)

func (*World) ObjectAppend added in v0.1.202602121754

func (w *World) ObjectAppend(peer_session_identities []ANDPeerSessionIdentity, objects []ObjectInfo)

func (*World) ObjectDelete added in v0.1.202602121754

func (w *World) ObjectDelete(peer_session_identities []ANDPeerSessionIdentity, objectIDs []uuid.UUID)

func (*World) PeerConnected added in v0.1.202602121754

func (w *World) PeerConnected(events ds.Queue, peer ani.IAbyssPeer)

PeerConnected must never raise EANDPeerDiscard event for the connected peer.

func (*World) PeerDisconnected added in v0.1.202602121754

func (w *World) PeerDisconnected(events ds.Queue, peer_id string)

We don't verify everything like we did for the other messages; we trust the caller. PeerDisconnected should raise EANDPeerDiscoard event for the peer.

func (*World) Peers added in v0.1.202602121754

func (w *World) Peers() []ani.IAbyssPeer

func (*World) RST added in v0.1.202602121754

func (w *World) RST(events ds.Queue, peer_session ANDPeerSession)

func (*World) SJN added in v0.1.202602121754

func (w *World) SJN(events ds.Queue, peer_session ANDPeerSession, member_infos []ANDPeerSessionIdentity)

func (*World) SOA added in v0.1.202602121754

func (w *World) SOA(events ds.Queue, peer_session ANDPeerSession, objects []ObjectInfo)

func (*World) SOD added in v0.1.202602121754

func (w *World) SOD(events ds.Queue, peer_session ANDPeerSession, objectIDs []uuid.UUID)

func (*World) SessionID added in v0.1.202602121754

func (w *World) SessionID() uuid.UUID

func (*World) TimerExpire added in v0.1.202602121754

func (w *World) TimerExpire(events ds.Queue)

Jump to

Keyboard shortcuts

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