network

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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

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

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

func NewBNCSonn

func NewBNCSonn(conn net.Conn) *BNCSonn

NewBNCSonn returns conn wrapped in W3GSPacketConn

func (*BNCSonn) Close

func (c *BNCSonn) Close() error

Close closes the connection

func (*BNCSonn) Conn

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

Conn returns the underlying net.Conn

func (*BNCSonn) NextClientPacket

func (c *BNCSonn) 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 (*BNCSonn) NextServerPacket

func (c *BNCSonn) 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 (*BNCSonn) RunClient

func (c *BNCSonn) RunClient(f Firer, 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 (*BNCSonn) RunServer

func (c *BNCSonn) RunServer(f Firer, 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 (*BNCSonn) Send

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

Send pkt to addr over net.Conn

func (*BNCSonn) SendRL

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

SendRL pkt to addr over net.Conn with rate limit

func (*BNCSonn) SetConn

func (c *BNCSonn) SetConn(conn net.Conn)

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

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)

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 Firer

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

Firer is the interface that wraps the basic Fire method

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 W3GSPacketConn

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