network

package
v0.0.0-...-e65b098 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_COMPRESSED_BITS = 4096
	MSG_MAX_PLAYERS     = ggponet.GGPO_MAX_PLAYERS
)
View Source
const (
	UDP_HEADER_SIZE           = 28 /* Size of IP + UDP headers */
	NUM_SYNC_PACKETS          = 5
	SYNC_RETRY_INTERVAL       = 2000
	SYNC_FIRST_RETRY_INTERVAL = 500
	RUNNING_RETRY_INTERVAL    = 200
	KEEP_ALIVE_INTERVAL       = 200
	QUALITY_REPORT_INTERVAL   = 1000
	NETWORK_STATS_INTERVAL    = 1000
	UDP_SHUTDOWN_TIMER        = 5000
	MAX_SEQ_DISTANCE          = (1 << 15)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callbacks

type Callbacks interface {
	OnMsg(recvAddr *net.UDPAddr, msg *NetplayMsgType)
}

type Event

type Event struct {
	Type              TypeEvent
	Input             lib.GameInput
	SavedFrame        lib.SavedFrame
	Synchronizing     Synchronizing
	DisconnectTimeout int64
}

func (*Event) Init

func (e *Event) Init(t TypeEvent)

type GameStateType

type GameStateType struct {
	PeerConnectStatus []ggponet.ConnectStatus
	StartFrame        int64
	Checksum          int64
}

type HdrType

type HdrType struct {
	Magic          uint64
	SequenceNumber uint64
	Type           MsgType
}

type InputAckType

type InputAckType struct {
	AckFrame int64
}

type InputType

type InputType struct {
	PeerConnectStatus   []ggponet.ConnectStatus
	StartFrame          int64
	DisconnectRequested bool
	AckFrame            int64
	NumBits             int64
	InputSize           int64  // XXX: shouldn't be in every single packet!
	Bits                []byte /* must be last */
}

type MsgType

type MsgType int64
const (
	Invalid MsgType = iota
	SyncRequest
	SyncReply
	Input
	QualityReport
	QualityReply
	KeepAlive
	InputAck
	GameState
)

type Netplay

type Netplay struct {
	Callbacks             *Callbacks
	Conn                  *net.UDPConn
	LocalAddr             *net.UDPAddr
	RemoteAddr            *net.UDPAddr
	Queue                 int64
	LastReceivedInput     lib.GameInput
	LastAckedInput        lib.GameInput
	LastSentInput         lib.GameInput
	LocalConnectStatus    []ggponet.ConnectStatus
	LocalFrameAdvantage   int64
	RemoteFrameAdvantage  int64
	RoundTripTime         int64
	PeerConnectStatus     []ggponet.ConnectStatus
	TimeSync              lib.TimeSync
	CurrentState          State
	PendingOutput         lib.RingBuffer
	LastSendTime          uint64
	MagicNumber           uint64
	RemoteMagicNumber     uint64
	Connected             bool
	NextSendSeq           uint64
	SendQueue             lib.RingBuffer
	EventQueue            lib.RingBuffer
	SendLatency           int64
	OopPercent            int64
	OoPacket              OoPacket
	NetplayState          StateType
	ReceiveChannel        chan NetplayMsgType
	ReceiveAddr           chan *net.UDPAddr
	DisconnectNotifyStart int64
	DisconnectNotifySent  bool
	NextRecvSeq           uint64
	DisconnectTimeout     int64
	DisconnectEventSent   bool
	LastRecvTime          uint64
	ShutDownTimeout       int64
	StatsStartTime        uint64
	KbpsSent              int64
	BytesSent             int64
	PacketsSent           int64
	IsInitialized         bool
}

func (*Netplay) Disconnect

func (n *Netplay) Disconnect() ggponet.GGPOErrorCode

func (*Netplay) GetEvent

func (n *Netplay) GetEvent(e *Event) bool

func (*Netplay) GetNetworkStats

func (n *Netplay) GetNetworkStats(s *ggponet.GGPONetworkStats)

func (*Netplay) GetPeerConnectStatus

func (n *Netplay) GetPeerConnectStatus(id int64, frame *int64) bool

func (*Netplay) HandlesMsg

func (n *Netplay) HandlesMsg(addr *net.UDPAddr) bool

func (*Netplay) HostConnection

func (n *Netplay) HostConnection(conn *net.UDPConn) *net.UDPConn

func (*Netplay) Init

func (n *Netplay) Init(remotePlayer ggponet.GGPOPlayer, localPort string, queue int64, status []ggponet.ConnectStatus, poll *lib.Poll, callbacks *Callbacks)

func (*Netplay) IsSynchronized

func (n *Netplay) IsSynchronized() bool

func (*Netplay) OnGameState

func (n *Netplay) OnGameState(msg *NetplayMsgType) bool

func (*Netplay) OnInput

func (n *Netplay) OnInput(msg *NetplayMsgType) bool

func (*Netplay) OnInputAck

func (n *Netplay) OnInputAck(msg *NetplayMsgType) bool

func (*Netplay) OnKeepAlive

func (n *Netplay) OnKeepAlive(msg *NetplayMsgType) bool

func (*Netplay) OnLoopPoll

func (n *Netplay) OnLoopPoll() bool

func (*Netplay) OnMsg

func (n *Netplay) OnMsg(msg *NetplayMsgType)

func (*Netplay) OnQualityReply

func (n *Netplay) OnQualityReply(msg *NetplayMsgType) bool

func (*Netplay) OnQualityReport

func (n *Netplay) OnQualityReport(msg *NetplayMsgType) bool

func (*Netplay) OnSyncReply

func (n *Netplay) OnSyncReply(msg *NetplayMsgType) bool

func (*Netplay) OnSyncRequest

func (n *Netplay) OnSyncRequest(msg *NetplayMsgType) bool

func (*Netplay) PumpSendQueue

func (n *Netplay) PumpSendQueue()

func (*Netplay) QueueEvent

func (n *Netplay) QueueEvent(e *Event)

func (*Netplay) Read

func (n *Netplay) Read()

func (*Netplay) RecommendFrameDelay

func (n *Netplay) RecommendFrameDelay() int64

func (*Netplay) SendGameState

func (n *Netplay) SendGameState(state lib.SavedFrame)

func (*Netplay) SendInput

func (n *Netplay) SendInput(input *lib.GameInput)

func (*Netplay) SendMsg

func (n *Netplay) SendMsg(msg *NetplayMsgType)

func (*Netplay) SendPendingOutput

func (n *Netplay) SendPendingOutput()

func (*Netplay) SendSyncRequest

func (n *Netplay) SendSyncRequest()

func (*Netplay) SetDisconnectNotifyStart

func (n *Netplay) SetDisconnectNotifyStart(timeout int64)

func (*Netplay) SetDisconnectTimeout

func (n *Netplay) SetDisconnectTimeout(timeout int64)

func (*Netplay) SetLocalFrameNumber

func (n *Netplay) SetLocalFrameNumber(localFrame int64)

func (*Netplay) Synchronize

func (n *Netplay) Synchronize()

func (*Netplay) UpdateNetworkStats

func (n *Netplay) UpdateNetworkStats()

func (*Netplay) Write

func (n *Netplay) Write(msg *NetplayMsgType)

type NetplayMsgType

type NetplayMsgType struct {
	ConnectStatus ggponet.ConnectStatus
	Hdr           HdrType
	SyncRequest   SyncRequestType
	SyncReply     SyncReplyType
	QualityReport QualityReportType
	QualityReply  QualityReplyType
	Input         InputType
	InputAck      InputAckType
	GameState     GameStateType
}

func (*NetplayMsgType) Init

func (n *NetplayMsgType) Init(t MsgType)

func (*NetplayMsgType) PacketSize

func (n *NetplayMsgType) PacketSize() int64

func (*NetplayMsgType) PayloadSize

func (n *NetplayMsgType) PayloadSize() int64

type OoPacket

type OoPacket struct {
	SendTime uint64
	DestAddr *net.UDPAddr
	Msg      *NetplayMsgType
}

type QualityReplyType

type QualityReplyType struct {
	Pong int64
}

type QualityReportType

type QualityReportType struct {
	FrameAdvantage int64 /* what's the other guy's frame advantage? */
	Ping           int64
}

type QueueEntry

type QueueEntry struct {
	QueueTime uint64
	DestAddr  *net.UDPAddr
	Msg       *NetplayMsgType
}

func (*QueueEntry) Init

func (q *QueueEntry) Init(time uint64, dst *net.UDPAddr, m *NetplayMsgType)

type RunningType

type RunningType struct {
	LastQualityReportTime    uint64
	LastNetworkStatsInterval uint64
	LastInputPacketRecvTime  uint64
}

type State

type State int64
const (
	Syncing State = iota
	Synchronzied
	Running
	Disconnected
)

type StateType

type StateType struct {
	Sync    SyncType
	Running RunningType
}

type SyncReplyType

type SyncReplyType struct {
	RandomReply uint64 /* OK, here's your random data back */
}

type SyncRequestType

type SyncRequestType struct {
	RandomRequest   uint64 /* please reply back with this random data */
	RemoteMagic     int64
	RemoteEndpoints int64
}

type SyncType

type SyncType struct {
	RoundTripsRemaining uint64
	Random              uint64
}

type Synchronizing

type Synchronizing struct {
	Total int64
	Count int64
}

type TypeEvent

type TypeEvent int64
const (
	EventUnknown            TypeEvent = -1
	EventConnected          TypeEvent = 0
	EventSynchronizing      TypeEvent = 1
	EventSynchronized       TypeEvent = 2
	EventInput              TypeEvent = 3
	EventDisconnected       TypeEvent = 4
	EventNetworkInterrupted TypeEvent = 5
	EventNetworkResumed     TypeEvent = 6
	EventGameState          TypeEvent = 7
)

Jump to

Keyboard shortcuts

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