raknet

package module
v0.0.0-...-34ce8e4 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 4 Imported by: 0

README

go-raknet

go-raknet is Raknet library written in Go. (developing a server only for now)

Most of the codes are based on JRaknet (by JRaknet-Team and Whirvis).

This project is not related to Jenkins Software LLC nor Oculus.

License

These codes are licensed under the MIT License.

MIT License

Copyright (c) 2018 beito

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Special Thanks

Thank you very much!

Based on

Library

and You!

Documentation

Index

Constants

View Source
const (

	// Version is version of go-raknet library
	Version = "1.0.0"

	// NetworkProtocol is a version of Raknet protocol
	NetworkProtocol = 9

	// MaxMTU is the maximum size of MTU
	MaxMTU = 1492

	// MinMTU is the minimum size of MTU
	MinMTU = 400

	// MaxChannel is the maximum size of order channel
	MaxChannels = 32

	// DefaultChannel is default channel
	DefaultChannel = 0

	// MaxSplitCount is the maximum size that can split
	MaxSplitCount = 128

	// MaxSplitsPerQueue is the maximum size of Queue
	MaxSplitsPerQueue = 4
)
View Source
const MaxMetadataValues = 0xff

Variables

View Source
var (

	// SendInterval
	SendInterval             time.Duration = 50 * time.Millisecond
	RecoverySendInterval                   = SendInterval
	PingSendInterval                       = 2500 * time.Millisecond
	DetectionSendInterval                  = PingSendInterval * 2
	SessionTimeout                         = DetectionSendInterval * 5
	MaxPacketsPerSecondBlock               = 1000 * 300 * time.Millisecond
)
View Source
var ConnctionTypeMagic = []byte{0x03, 0x08, 0x05, 0x0b, 0x43, 0x54, 0x49}

ConnectionTypeMagic is the magic for ConnectionType.

View Source
var ConnectionGoRaknet = &ConnectionType{
	UUID:    uuid.FromStringOrNil("495248b9-d485-4389-acd0-175fdb2233cf"),
	Name:    "GoRaknet",
	Lang:    "Go",
	Version: "1.0.0",
}

ConnectionGoRaknet is a connection from go-raknet.

View Source
var ConnectionVanilla = &ConnectionType{
	Name:      "Vanilla",
	IsVanilla: true,
}

ConnectionVanilla is a connection from a vanilla client or an unknown implementation

View Source
var Magic = []byte{0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78}

Magic is Raknet offline message data id using offline connection in Raknet

View Source
var MaxPacketsPerSecond = 500

MaxPacketsPerSecond is the maximum size that can send per second

Functions

This section is empty.

Types

type ConnectionType

type ConnectionType struct {
	UUID      uuid.UUID
	Name      string
	Lang      string
	Version   string
	Metadata  Metadata
	IsVanilla bool
}

ConnectionType used to signify which implementation of the Raknet protocol

type Latency

type Latency struct {
	// totalLatency is the total latency time
	TotalLatency time.Duration

	// latency is the average latency time
	Latency time.Duration

	// lastLatency is the last latency time
	LastLatency time.Duration

	// lowestLatency is the lowest latency time
	LowestLatency time.Duration

	// highestLatency is the highest latency time
	HighestLatency time.Duration
	// contains filtered or unexported fields
}

func (*Latency) AddRaw

func (lat *Latency) AddRaw(raw time.Duration)

type Logger

type Logger interface {
	Info(msg ...interface{})
	Warn(msg ...interface{})
	Fatal(msg ...interface{})
	Debug(msg ...interface{})
}

Logger is a logger interface supported

type Metadata

type Metadata map[string]string

Metadata is metadata for ConnectionType

type Packet

type Packet interface {

	// ID returns a packet id
	ID() byte

	// Encode encodes the packet
	Encode() error

	// Decode decodes the packet
	Decode() error

	// Bytes returns encoded bytes
	Bytes() []byte

	// SetBytes sets bytes to decode
	SetBytes([]byte)

	// New returns new packet
	New() Packet
}

Packet is a basic packet interface

type Protocol

type Protocol interface {

	// RegisterPackets registers packets
	// It's called in starting the server
	RegisterPackets()

	// Packet returns a packet with id
	Packet(id byte) Packet

	//Packets returns all registered packets
	Packets() []Packet
}

Protocol is Raknet protocol's packets manager

type Record

type Record struct {
	Index    int
	EndIndex int
}

Record is ack numbers container for acknowledge packet

func (*Record) Count

func (record *Record) Count() int

Count returns the number of Record

func (*Record) Equals

func (record *Record) Equals(sub *Record) bool

Equals returns whether the record equals record sub

func (*Record) IsRanged

func (record *Record) IsRanged() bool

IsRanged returns whether the record is range

func (*Record) Numbers

func (record *Record) Numbers() []int

Numbers returns numbers recorded in Record as array

type Reliability

type Reliability int

Reliability decides reliable and ordered of packet when sending Thanks: http://www.jenkinssoftware.com/raknet/manual/Doxygen/PacketPriority_8h.html#e41fa01235e99dced384d137fa874a7e

const (
	// Unreliable is normal UDP packet.
	Unreliable Reliability = iota

	// UnreliableSequenced is the same as Unreliable. but it has Sequenced.
	UnreliableSequenced

	Reliable
	ReliableOrdered
	ReliableSequenced
	UnreliableWithACKReceipt
	ReliableWithACKReceipt
	ReliableOrderedWithACKReceipt
)

func ReliabilityBinary

func ReliabilityBinary(b byte) Reliability

ReliabilityBinary returns Reliability from binary

func (Reliability) IsNeededACK

func (r Reliability) IsNeededACK() bool

IsNeededACK returns whether reliability need ack

func (Reliability) IsOrdered

func (r Reliability) IsOrdered() bool

IsOrdered returns whether reliability has ordered

func (Reliability) IsReliable

func (r Reliability) IsReliable() bool

IsReliable returns whether reliability has reliable

func (Reliability) IsSequenced

func (r Reliability) IsSequenced() bool

IsSequenced returns whether reliability has sequenced

func (Reliability) ToBinary

func (r Reliability) ToBinary() byte

ToBinary encode reliability to bytes

type SystemAddress

type SystemAddress struct {
	IP   net.IP
	Port uint16
}

SystemAddress is internal address for Raknet

func NewSystemAddress

func NewSystemAddress(addr string, port uint16) *SystemAddress

NewSystemAddress returns a new SystemAddress from string

func NewSystemAddressBytes

func NewSystemAddressBytes(addr []byte, port uint16) *SystemAddress

NewSystemAddress returns a new SystemAddress from bytes

func (*SystemAddress) Equal

func (addr *SystemAddress) Equal(sub *SystemAddress) bool

Equal returns whether sub is the same address

func (*SystemAddress) IsLoopback

func (addr *SystemAddress) IsLoopback() bool

IsLoopback returns whether this is loopback address

func (*SystemAddress) SetLoopback

func (addr *SystemAddress) SetLoopback()

SetLoopback sets loopback address

func (*SystemAddress) String

func (addr *SystemAddress) String() string

String returns as string Format: 192.168.11.1:8080, [fc00::]:8080

func (*SystemAddress) Version

func (addr *SystemAddress) Version() int

Version returns the ip address version (4 or 6)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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