gp

package
v0.0.0-...-4a740ba Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinPacketLen is minimum packet length of GP packet
	// 320bit header + 128bit min payload
	MinPacketLen = 56
)

Variables

View Source
var (
	ErrPacketTooShort = er.New("urn:giti:gp.protocol:error:packet-too-short").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Packet Too Short",
		"Giti packet is empty or too short than standard header. It must include 44Byte header plus 16Byte min Payload",
		"",
		"").Save()

	ErrPacketArrivedAnterior = er.New("urn:giti:gp.protocol:error:packet-arrived-anterior").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Packet Arrived Anterior",
		"New packet arrive before some expected packet arrived. Usually cause of drop packet detection or high latency occur for some packet",
		"",
		"").Save()

	ErrPacketArrivedPosterior = er.New("urn:giti:gp.protocol:error:packet-arrived-posterior").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Packet Arrived Posterior",
		"New packet arrive after some expected packet arrived. Usually cause of drop packet detection or high latency occur for some packet",
		"",
		"").Save()
)

Errors

View Source
var (
	AddrNil = Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)

Some global address

Functions

func CheckPacket

func CheckPacket(p []byte) protocol.Error

CheckPacket will check packet for any bad situation! Always check packet before use any other packet methods otherwise panic occur!

func Decrypt

func Decrypt(payload []byte, cipher protocol.Cipher) (frames []byte, err protocol.Error)

Decrypt use in encrypted connection from Apps to Apps!

func DecryptRouting

func DecryptRouting(packet []byte, cipher protocol.Cipher) (err protocol.Error)

DecryptRouting usually use in encrypted connection from OS to GP Router!

func Encrypt

func Encrypt(frames []byte, cipher protocol.Cipher) (payload []byte, err protocol.Error)

Encrypt use in encrypted connection from Apps to Apps!

func EncryptRouting

func EncryptRouting(packet []byte, cipher protocol.Cipher) (err protocol.Error)

EncryptRouting usually use in encrypted connection from OS to GP Router!

func GetPacketNumber

func GetPacketNumber(p []byte) uint64

GetPacketNumber returns packet number

func GetPayload

func GetPayload(p []byte) []byte

GetPayload returns payload that means all data after packetNumber

Types

type Addr

type Addr [16]byte

Addr present GP address with needed methods

func GetDestinationAddr

func GetDestinationAddr(p []byte) (addr Addr)

GetDestinationAddr returns full destination GP address.

func GetSourceAddr

func GetSourceAddr(p []byte) (addr Addr)

GetSourceAddr returns full source GP address.

func (Addr) AppID

func (addr Addr) AppID() uint16

AppID returns app ID in the user scope.

func (Addr) PlanetID

func (addr Addr) PlanetID() uint16

PlanetID returns planet ID.

func (Addr) RouterID

func (addr Addr) RouterID() uint32

RouterID returns router ID in the society scope.

func (Addr) SetAppID

func (addr Addr) SetAppID(id uint32)

SetAppID set app ID in given Addr.

func (Addr) SetPlanetID

func (addr Addr) SetPlanetID(id uint16)

SetPlanetID set planet ID in given Addr.

func (Addr) SetRouterID

func (addr Addr) SetRouterID(id uint32)

SetRouterID set router ID in given Addr.

func (Addr) SetSocietyID

func (addr Addr) SetSocietyID(id uint32)

SetSocietyID set society ID in given Addr.

func (Addr) SetUserID

func (addr Addr) SetUserID(id uint32)

SetUserID set user ID in given Addr.

func (Addr) SocietyID

func (addr Addr) SocietyID() uint32

SocietyID returns society ID.

func (Addr) UserID

func (addr Addr) UserID() uint32

UserID returns user ID in the router scope.

type AppMultiplexer

type AppMultiplexer struct{}

func (*AppMultiplexer) HeaderID

func (appMux *AppMultiplexer) HeaderID() protocol.NetworkLinkNextHeaderID

func (*AppMultiplexer) Init

func (appMux *AppMultiplexer) Init() (err protocol.Error)

MakeGPNetwork register app to OS GP router and start handle income GP packets.

func (*AppMultiplexer) Receive

func (appMux *AppMultiplexer) Receive(linkConn protocol.NetworkLinkConnection, packet []byte)

Receive handle GP packet with any application protocol and response just some basic data! Protocol Standard : https://github.com/GeniusesGroup/RFCs/blob/master/Giti-Network.md

func (*AppMultiplexer) Shutdown

func (appMux *AppMultiplexer) Shutdown()

Shutdown the listener when the application closes or force to closes by not recovered panic!

type Connection

type Connection struct {

	/* Connection data */
	ID         [32]byte
	StreamPool StreamPool
	State      protocol.ConnectionState
	Weight     protocol.ConnectionWeight

	/* Security data */
	AccessControl authorization.AccessControl

	connection.Metric
	// contains filtered or unexported fields
}

Connection indicate the https://github.com/balacode/udpt/blob/main/sender.go

func EstablishNewConnectionByDomainID

func EstablishNewConnectionByDomainID(domainID [32]byte) (conn *Connection, err protocol.Error)

EstablishNewConnectionByDomainID make new connection by peer domain ID and initialize it!

func EstablishNewConnectionByPeerAdd

func EstablishNewConnectionByPeerAdd(gpAddr Addr) (conn *Connection, err protocol.Error)

EstablishNewConnectionByPeerAdd make new connection by peer GP and initialize it!

func MakeNewGuestConnection

func MakeNewGuestConnection() (conn *Connection, err protocol.Error)

MakeNewGuestConnection make new connection and register on given stream due to it is first attempt connect to server!

func (*Connection) Addr

func (conn *Connection) Addr() [16]byte

func (*Connection) AddrType

func (conn *Connection) AddrType() NetworkLinkNextHeaderID

func (*Connection) Cipher

func (conn *Connection) Cipher() Cipher

func (*Connection) DelegateUserID

func (conn *Connection) DelegateUserID() [32]byte

func (*Connection) DelegateUserType

func (conn *Connection) DelegateUserType() UserType

func (*Connection) DomainName

func (conn *Connection) DomainName() string

func (*Connection) ID

func (conn *Connection) ID() uint32

func (*Connection) MTU

func (conn *Connection) MTU() int

func (*Connection) MakeIncomeStream

func (conn *Connection) MakeIncomeStream(streamID uint32) (st protocol.Stream, err protocol.Error)

MakeIncomeStream make and return the new stream with income ID! Never make Stream instance by hand, This function can improve by many ways!

func (*Connection) MakeOutcomeStream

func (conn *Connection) MakeOutcomeStream(streamID uint32) (st *Stream, err protocol.Error)

MakeOutcomeStream make and return the new stream with outcome ID! Never make Stream instance by hand, This function can improve by many ways!

func (*Connection) MakeSubscriberStream

func (conn *Connection) MakeSubscriberStream() (st *Stream)

MakeSubscriberStream make new Publish–Subscribe stream!

func (*Connection) Receive

func (conn *Connection) Receive(packet []byte)

Receive use for default and empty switch port due to non of ports can be nil!

func (*Connection) SetThingID

func (conn *Connection) SetThingID(thingID [32]byte)

SetThingID set thingID only if it is not set before

func (*Connection) ThingID

func (conn *Connection) ThingID() [32]byte

func (*Connection) UserID

func (conn *Connection) UserID() [32]byte

func (*Connection) UserType

func (conn *Connection) UserType() UserType

type OSMultiplexer

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

func (*OSMultiplexer) HeaderID

func (*OSMultiplexer) Init

func (osMux *OSMultiplexer) Init()

MakeGPNetwork register app to OS GP router and start handle income GP packets.

func (*OSMultiplexer) Receive

func (osMux *OSMultiplexer) Receive(conn protocol.NetworkLinkConnection, packet []byte)

Receive handle GP packet with any application protocol and response just some basic data! Protocol Standard : https://github.com/GeniusesGroup/RFCs/blob/master/Giti-Network.md

func (*OSMultiplexer) RegisterAppMultiplexer

func (osMux *OSMultiplexer) RegisterAppMultiplexer(appMux protocol.NetworkTransportMultiplexer)

RegisterAppMultiplexer will register multiplexer only if it is GP multiplexer.

func (*OSMultiplexer) Shutdown

func (osMux *OSMultiplexer) Shutdown()

Shutdown the listener when the application closes or force to closes by not recovered panic.

func (*OSMultiplexer) UnRegisterAppMultiplexer

func (osMux *OSMultiplexer) UnRegisterAppMultiplexer(appMux protocol.NetworkTransportMultiplexer)

type Stream

type Stream struct {
	Weight protocol.ConnectionWeight // 16 queue for priority weight of the streams exist.

	/* Metrics */
	TotalPacket     uint32 // Expected packets count that must received!
	PacketReceived  uint32 // Count of packets received!
	LastPacketID    uint32 // Last send or received Packet use to know order of packets!
	PacketDropCount uint8  // Count drop packets to prevent some attacks type!
	// contains filtered or unexported fields
}

Stream use to send or receive data on specific connection. It can pass to logic layer to give data access to developer! Data flow can be up to down (parse raw income data) or down to up (encode app data with respect MTU) If OutcomePayload not present stream is UnidirectionalStream otherwise it is BidirectionalStream!

func MakeNewStream

func MakeNewStream() (st *Stream, err protocol.Error)

MakeNewStream use to make new stream without any connection exist yet! TODO::: due to IPv4&&IPv6 support we need this func! Remove it when remove those support!

func (*Stream) Authorize

func (st *Stream) Authorize() (err protocol.Error)

Authorize authorize request by data in related stream and connection.

func (*Stream) Close

func (st *Stream) Close()

CloseStream delete given Stream from pool

func (*Stream) Connection

func (st *Stream) Connection() protocol.Connection

func (*Stream) ID

func (st *Stream) ID() uint32

func (*Stream) IncomeData

func (st *Stream) IncomeData() protocol.Codec

func (*Stream) OutcomeData

func (st *Stream) OutcomeData() protocol.Codec

func (*Stream) ProtocolID

func (st *Stream) ProtocolID() protocol.NetworkApplicationProtocolID

func (*Stream) SendRequest

func (st *Stream) SendRequest() (err protocol.Error)

SendRequest use for default and empty switch port due to non of ports can be nil! SendAndWait register stream in send pool and block caller until response ready to read.

func (*Stream) SendResponse

func (st *Stream) SendResponse() (err protocol.Error)

SendResponse register stream in send pool. Usually use to send response stream.

func (*Stream) Service

func (st *Stream) Service() protocol.Service

func (*Stream) SetIncomeData

func (st *Stream) SetIncomeData(codec protocol.Codec)

func (*Stream) SetOutcomeData

func (st *Stream) SetOutcomeData(codec protocol.Codec)

func (*Stream) SetService

func (st *Stream) SetService(service protocol.Service)

SetService check and if it is first time register given service for the stream.

func (*Stream) SetState

func (st *Stream) SetState(state protocol.ConnectionState)

SetState change state of stream and send notification on stream StateChannel.

func (*Stream) State

func (st *Stream) State() chan protocol.ConnectionState

func (*Stream) Status

func (st *Stream) Status() protocol.ConnectionState

type StreamPool

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

StreamPool set & get streams in a pool by ID!

func (*StreamPool) Init

func (sp *StreamPool) Init()

Init initialize the pool

func (*StreamPool) OutcomeStream

func (sp *StreamPool) OutcomeStream(service protocol.Service) (stream protocol.Stream, err protocol.Error)

OutcomeStream make the stream and returns it!

func (*StreamPool) RegisterStream

func (sp *StreamPool) RegisterStream(st protocol.Stream)

RegisterStream save given Stream to pool

func (*StreamPool) Stream

func (sp *StreamPool) Stream(id uint32) protocol.Stream

Stream returns Stream from pool if exists by given ID!

Jump to

Keyboard shortcuts

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