network

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MPL-2.0 Imports: 16 Imported by: 38

Documentation

Overview

Package network implements common utilities for higher-level (emulated) Warcraft III network components.

Index

Constants

View Source
const NoTimeout = time.Duration(-1)

NoTimeout constant to read/write without deadline

View Source
const WSAECONNABORTED = 10053

WSAECONNABORTED is ECONNABORTED on Windows

View Source
const WSAECONNREFUSED = 10061

WSAECONNREFUSED is ECONNREFUSED on Windows

View Source
const WSAECONNRESET = 10054

WSAECONNRESET is ECONNRESET on Windows

View Source
const WSAENOTCONN = 10057

WSAENOTCONN is ENOTCONN on Windows

View Source
const WSAESHUTDOWN = 10058

WSAESHUTDOWN is ESHUTDOWN on Windows

Variables

View Source
var W3GSBroadcastAddr = net.UDPAddr{IP: net.IPv4bcast, Port: 6112}

W3GSBroadcastAddr is used to broadcast W3GS packets to LAN

Functions

func Deadline added in v1.6.0

func Deadline(timeout time.Duration) time.Time

Deadline for given timeout

func IsCloseError added in v1.5.0

func IsCloseError(err error) bool

IsCloseError checks if err indicates a (cleanly) closed connection

func IsRefusedError added in v1.5.0

func IsRefusedError(err error) bool

IsRefusedError checks if err indicates a refused connection

func IsSysCallError

func IsSysCallError(err error, errno ...syscall.Errno) bool

IsSysCallError checks if error is one of syscall.Errno

func IsTemporary added in v1.5.0

func IsTemporary(err error) bool

IsTemporary checks is error is temporary

func IsTimeout added in v1.5.0

func IsTimeout(err error) bool

IsTimeout checks is error is timeout

func IsUnexpectedCloseError added in v1.5.0

func IsUnexpectedCloseError(err error) bool

IsUnexpectedCloseError checks if err indicates an unexpectedly closed connection

func IsUseClosedNetworkError

func IsUseClosedNetworkError(err error) bool

IsUseClosedNetworkError checks if net.error is poll.ErrNetClosed

func Topic added in v1.5.0

func Topic(s string) interface{}

Topic literal

func UnnestError

func UnnestError(err error) error

UnnestError retrieves the innermost error

Types

type AsyncError

type AsyncError struct {
	Src string
	Err error
}

AsyncError keeps track of where a non-fatal asynchronous error orignated

func (*AsyncError) Error

func (e *AsyncError) Error() string

func (*AsyncError) Temporary added in v1.5.0

func (e *AsyncError) Temporary() bool

Temporary error

func (*AsyncError) Timeout added in v1.5.0

func (e *AsyncError) Timeout() bool

Timeout occurred

type BNCSConn added in v1.2.0

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

BNCSConn manages a TCP connection that transfers BNCS packets from/to client. Public methods/fields are thread-safe unless explicitly stated otherwise

func NewBNCSConn added in v1.2.0

func NewBNCSConn(conn net.Conn, fact bncs.PacketFactory, enc bncs.Encoding) *BNCSConn

NewBNCSConn returns conn wrapped in BNCSConn

func (*BNCSConn) Close added in v1.2.0

func (c *BNCSConn) Close() error

Close the connection

func (*BNCSConn) Conn added in v1.2.0

func (c *BNCSConn) Conn() net.Conn

Conn returns the underlying net.Conn

func (*BNCSConn) NextPacket added in v1.5.0

func (c *BNCSConn) NextPacket(timeout time.Duration) (bncs.Packet, error)

NextPacket waits for the next packet (with given timeout) and returns its deserialized representation Not safe for concurrent invocation

func (*BNCSConn) Run added in v1.5.0

func (c *BNCSConn) Run(f Emitter, timeout time.Duration) error

Run reads packets (with given max time between packets) from Conn and emits an event for each received packet Not safe for concurrent invocation

func (*BNCSConn) Send added in v1.2.0

func (c *BNCSConn) Send(pkt bncs.Packet) (int, error)

Send pkt to addr over net.Conn

func (*BNCSConn) SendRL added in v1.2.0

func (c *BNCSConn) SendRL(pkt bncs.Packet) (int, error)

SendRL pkt to addr over net.Conn with rate limit

func (*BNCSConn) SetConn added in v1.2.0

func (c *BNCSConn) SetConn(conn net.Conn, fact bncs.PacketFactory, enc bncs.Encoding)

SetConn closes the old connection and starts using the new net.Conn

func (*BNCSConn) SetWriteTimeout added in v1.6.0

func (c *BNCSConn) SetWriteTimeout(wto time.Duration)

SetWriteTimeout for Send() calls

func (*BNCSConn) Write added in v1.6.0

func (c *BNCSConn) Write(b []byte) (int, error)

Write implements io.Writer

type CAPIConn added in v1.2.0

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

CAPIConn manages a websocket connection that processes CAPI requests. Public methods/fields are thread-safe unless explicitly stated otherwise

func NewCAPIConn added in v1.2.0

func NewCAPIConn(conn *websocket.Conn) *CAPIConn

NewCAPIConn returns conn wrapped in CAPIConn

func (*CAPIConn) Close added in v1.2.0

func (c *CAPIConn) Close() error

Close the connection

func (*CAPIConn) Conn added in v1.2.0

func (c *CAPIConn) Conn() *websocket.Conn

Conn returns the underlying net.Conn

func (*CAPIConn) NextPacket added in v1.2.0

func (c *CAPIConn) NextPacket(timeout time.Duration) (*capi.Packet, error)

NextPacket waits for the next packet (with given timeout) and returns its deserialized representation Not safe for concurrent invocation

func (*CAPIConn) Run added in v1.2.0

func (c *CAPIConn) Run(f Emitter, timeout time.Duration) error

Run reads packets (with given max time between packets) from Conn and fires an event through f for each received packet Not safe for concurrent invocation

func (*CAPIConn) Send added in v1.2.0

func (c *CAPIConn) Send(pkt *capi.Packet) error

Send pkt to addr over net.Conn

func (*CAPIConn) SetConn added in v1.2.0

func (c *CAPIConn) SetConn(conn *websocket.Conn)

SetConn closes the old connection and starts using the new net.Conn

func (*CAPIConn) SetWriteTimeout added in v1.6.0

func (c *CAPIConn) SetWriteTimeout(wto time.Duration)

SetWriteTimeout for Send() calls

type Emitter added in v1.1.0

type Emitter interface {
	Fire(a EventArg, o ...EventArg) bool
}

Emitter is the interface that wraps the basic Fire method

type Event

type Event struct {
	Arg EventArg
	Opt []EventArg
	// contains filtered or unexported fields
}

Event structure passed to event handlers

func (*Event) PreventNext

func (e *Event) PreventNext()

PreventNext prevents any other handlers from being called for this event

type EventArg

type EventArg interface{}

EventArg identifies an event (and with it the type of its Arg)

type EventEmitter

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

EventEmitter is an event emitter based on argument types For every type, a listener can register callbacks. Callbacks will be fired in reverse order of registration. The structure is thread-safe and functions can be called from multiple goroutines at the same time.

func (*EventEmitter) Fire

func (e *EventEmitter) Fire(a EventArg, o ...EventArg) bool

Fire new event of type a

func (*EventEmitter) Off

func (e *EventEmitter) Off(id EventID)

Off stops id from listening to future events

func (*EventEmitter) OffAll

func (e *EventEmitter) OffAll(a EventArg)

OffAll clears the current listeners for events of type a

func (*EventEmitter) On

On an event of type a is, call handler h

func (*EventEmitter) Once

func (e *EventEmitter) Once(a EventArg, h EventHandler) EventID

Once an event of type a is fired, call handler h once

type EventHandler

type EventHandler func(*Event)

EventHandler callback function

type EventID

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

EventID identifies a single event handler

type Listener added in v1.2.0

type Listener interface {
	On(a EventArg, h EventHandler) EventID
	Once(a EventArg, h EventHandler) EventID
	Off(id EventID)
	OffAll(a EventArg)
}

Listener is the interface that wraps the basic On/Once methods

type RWMutex

type RWMutex struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RWMutex implements a read-preferring readers–writer lock

func (*RWMutex) RLock

func (m *RWMutex) RLock()

RLock acquires a readers-lock

func (*RWMutex) RUnlock

func (m *RWMutex) RUnlock()

RUnlock decrements the readers-lock

type RunStart

type RunStart struct{}

RunStart event

type RunStop

type RunStop struct{}

RunStop event

type W3GSConn

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

W3GSConn manages a TCP connection that transfers W3GS packets. Public methods/fields are thread-safe unless explicitly stated otherwise

func NewW3GSConn

func NewW3GSConn(conn net.Conn, fact w3gs.PacketFactory, enc w3gs.Encoding) *W3GSConn

NewW3GSConn returns conn wrapped in W3GSConn

func (*W3GSConn) Close

func (c *W3GSConn) Close() error

Close the connection

func (*W3GSConn) Conn

func (c *W3GSConn) Conn() net.Conn

Conn returns the underlying net.Conn

func (*W3GSConn) NextPacket

func (c *W3GSConn) NextPacket(timeout time.Duration) (w3gs.Packet, error)

NextPacket waits for the next packet (with given timeout) and returns its deserialized representation Not safe for concurrent invocation

func (*W3GSConn) Run

func (c *W3GSConn) Run(f Emitter, timeout time.Duration) error

Run reads packets (with given max time between packets) from Conn and fires an event through f for each received packet Not safe for concurrent invocation

func (*W3GSConn) Send

func (c *W3GSConn) Send(pkt w3gs.Packet) (int, error)

Send pkt to addr over net.Conn

func (*W3GSConn) SetConn

func (c *W3GSConn) SetConn(conn net.Conn, fact w3gs.PacketFactory, enc w3gs.Encoding)

SetConn closes the old connection and starts using the new net.Conn

func (*W3GSConn) SetWriteTimeout added in v1.6.0

func (c *W3GSConn) SetWriteTimeout(wto time.Duration)

SetWriteTimeout for Send() calls

func (*W3GSConn) Write added in v1.6.0

func (c *W3GSConn) Write(b []byte) (int, error)

Write implements io.Writer

type W3GSPacketConn

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

W3GSPacketConn manages a UDP connection that transfers W3GS packets. Public methods/fields are thread-safe unless explicitly stated otherwise

func NewW3GSPacketConn

func NewW3GSPacketConn(conn net.PacketConn, fact w3gs.PacketFactory, enc w3gs.Encoding) *W3GSPacketConn

NewW3GSPacketConn returns conn wrapped in W3GSPacketConn

func (*W3GSPacketConn) Broadcast

func (c *W3GSPacketConn) Broadcast(pkt w3gs.Packet) (int, error)

Broadcast a packet over LAN

func (*W3GSPacketConn) Close

func (c *W3GSPacketConn) Close() error

Close the connection

func (*W3GSPacketConn) Conn

func (c *W3GSPacketConn) Conn() net.PacketConn

Conn returns the underlying net.PacketConn

func (*W3GSPacketConn) NextPacket

func (c *W3GSPacketConn) NextPacket(timeout time.Duration) (w3gs.Packet, net.Addr, error)

NextPacket waits for the next packet (with given timeout) and returns its deserialized representation Not safe for concurrent invocation

func (*W3GSPacketConn) Run

func (c *W3GSPacketConn) Run(f Emitter, timeout time.Duration) error

Run reads packets (with given max time between packets) from Conn and emits an event for each received packet Not safe for concurrent invocation

func (*W3GSPacketConn) Send

func (c *W3GSPacketConn) Send(addr net.Addr, pkt w3gs.Packet) (int, error)

Send pkt to addr over net.PacketConn

func (*W3GSPacketConn) SetConn

func (c *W3GSPacketConn) SetConn(conn net.PacketConn, fact w3gs.PacketFactory, enc w3gs.Encoding)

SetConn closes the old connection and starts using the new net.PacketConn

func (*W3GSPacketConn) SetWriteTimeout added in v1.6.0

func (c *W3GSPacketConn) SetWriteTimeout(wto time.Duration)

SetWriteTimeout for Send() calls

Directories

Path Synopsis
Package bnet implements a mocked BNCS client that can be used to interact with BNCS servers.
Package bnet implements a mocked BNCS client that can be used to interact with BNCS servers.
Package chat implements the official classic Battle.net chat API.
Package chat implements the official classic Battle.net chat API.
Package dummy implements a mocked Warcraft III game client that can be used to add dummy players to lobbies.
Package dummy implements a mocked Warcraft III game client that can be used to add dummy players to lobbies.
Package lan implements a mocked Warcraft III LAN client that can be used to discover local games.
Package lan implements a mocked Warcraft III LAN client that can be used to discover local games.
Package lobby implements a mocked Warcraft III game server that can be used to host lobbies.
Package lobby implements a mocked Warcraft III game server that can be used to host lobbies.
Package peer implements a mocked Warcraft III client that can be used to manage peer connections in lobbies.
Package peer implements a mocked Warcraft III client that can be used to manage peer connections in lobbies.

Jump to

Keyboard shortcuts

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