network

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const WSAECONNREFUSED = 10061

WSAECONNREFUSED is ECONNREFUSED on Windows

View Source
const WSAECONNRESET = 10054

WSAECONNRESET is ECONNRESET 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 IsConnClosedError

func IsConnClosedError(err error) bool

IsConnClosedError checks if net.error is a "connection closed" error

func IsConnRefusedError added in v1.2.0

func IsConnRefusedError(err error) bool

IsConnRefusedError checks if net.error is a "connection refused" error

func IsSysCallError

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

IsSysCallError checks if net.error is syscall.Errno

func IsUseClosedNetworkError

func IsUseClosedNetworkError(err error) bool

IsUseClosedNetworkError checks if net.error is poll.ErrNetClosed

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

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) *BNCSConn

NewBNCSConn returns conn wrapped in BNCSConn

func (*BNCSConn) Close added in v1.2.0

func (c *BNCSConn) Close() error

Close closes the connection

func (*BNCSConn) Conn added in v1.2.0

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

Conn returns the underlying net.Conn

func (*BNCSConn) NextClientPacket added in v1.2.0

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

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

func (*BNCSConn) NextServerPacket added in v1.2.0

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

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

func (*BNCSConn) RunClient added in v1.2.0

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

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

func (*BNCSConn) RunServer added in v1.2.0

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

RunServer reads client 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)

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

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 closes 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

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) *W3GSConn

NewW3GSConn returns conn wrapped in W3GSConn

func (*W3GSConn) Close

func (c *W3GSConn) Close() error

Close closes 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)

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

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) *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 closes 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)

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

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 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