chaparkhane

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: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServerStateStop indicate server had been stopped
	ServerStateStop int = iota
	// ServerStateRunning indicate server is working
	ServerStateRunning
	// ServerStateStopping indicate server want to stop
	ServerStateStopping
	// ServerStateStarting indicate server plan to start and working on it
	ServerStateStarting
)

Server Status

View Source
const (
	// ServiceStatePreAlpha refers to all activities performed during the software project before formal testing.
	ServiceStatePreAlpha uint8 = iota
	// ServiceStateAlpha is the first phase to begin software testing
	ServiceStateAlpha
	// ServiceStateBeta generally begins when the software is feature complete but likely to contain a number of known or unknown bugs.
	ServiceStateBeta
	// ServiceStatePerpetualBeta where new features are continually added to the software without establishing a final "stable" release.
	// This technique may allow a developer to delay offering full support and responsibility for remaining issues.
	ServiceStatePerpetualBeta
	// ServiceStateOpenBeta is for a larger group, or anyone interested.
	ServiceStateOpenBeta
	// ServiceStateClosedBeta is released to a restricted group of individuals for a user test by invitation.
	ServiceStateClosedBeta
	// ServiceStateReleaseCandidate also known as "going silver", is a beta version with potential to be a stable product,
	// which is ready to release unless significant bugs emerge
	ServiceStateReleaseCandidate
	// ServiceStateStableRelease Also called production release,
	// the stable release is the last release candidate (RC) which has passed all verifications / tests.
	ServiceStateStableRelease
	// ServiceStateEndOfLife indicate no longer supported and continue its existence until to ExpiryDate!
	ServiceStateEndOfLife
)

Service Status https://en.wikipedia.org/wiki/Software_release_life_cycle

View Source
const (
	// UserConnectionStateClosed indicate connection had been closed
	UserConnectionStateClosed uint8 = iota
	// UserConnectionStateOpen indicate connection is open and ready to use
	UserConnectionStateOpen
	// UserConnectionStateRateLimited indicate connection limited due to higher usage than permitted!
	UserConnectionStateRateLimited
	// UserConnectionStateOpening indicate connection plan to open and not ready to accept stream!
	UserConnectionStateOpening
	// UserConnectionStateClosing indicate connection plan to close and not accept new stream
	UserConnectionStateClosing
	// UserConnectionStateNotResponse indicate peer not response to recently send request!
	UserConnectionStateNotResponse
)

UserConnection Status

Variables

View Source
var DefaultServer = &defaultServer

DefaultServer use as default server.

Functions

func Log

func Log(a ...interface{})

Log will show log in standard console & append log to buffer to save them later.

func SaveLogToStorage

func SaveLogToStorage(saveLocation string)

SaveLogToStorage use to make||flush to achaemenid.log if needed!

Types

type MakeNewRouterConnectionReq

type MakeNewRouterConnectionReq struct {
	RouterID     uint32
	Path         []byte
	MaxBandwidth uint64
	Signature    [256]byte
}

MakeNewRouterConnectionReq is the request structure of MakeNewRouterConnection()

type MakeNewUserConnectionReq

type MakeNewUserConnectionReq struct {
	UserID        [16]byte
	ThingID       [16]byte
	UserPublicKey [32]byte
	Path          []byte
	MaxBandwidth  uint64
	Signature     [256]byte
}

MakeNewUserConnectionReq is the request structure of MakeNewUserConnection()

type MakeNewXPConnectionReq

type MakeNewXPConnectionReq struct {
	XPID         uint32
	RouterID     uint32
	Path         []byte
	MaxBandwidth uint64
	Signature    [256]byte
}

MakeNewXPConnectionReq is the request structure of MakeNewXPConnection()

type Manifest

type Manifest struct {
	AppID               [16]byte // Application ID
	PlatformID          uint32   // XP part of GPs!
	RouterID            uint32   // Router part of GPs!
	Email               string
	Icon                string
	AuthorizedUsers     [][16]byte // Just accept request from these users!
	SupportedLanguages  []uint32
	ManifestLanguages   []uint32
	Name                []string
	Description         []string
	TermsOfService      []string
	Licence             []string
	TAGS                []string // Use to categorized apps e.g. Music, GPS, ...
	RequestedPermission []uint32 // ServiceIDs from PersiaOS services e.g. InternetInBackground, Notification, ...
	TechnicalInfo       TechnicalInfo
}

Manifest use to store server manifest data All string slice is multi language and in order by ManifestLanguages order

type PacketHandler

type PacketHandler func(s *Server, conn *UserConnection)

PacketHandler show how to write packet handler function

type Server

type Server struct {
	Status            int // States locate in this file.
	Manifest          Manifest
	Services          services
	UserConnections   userConnections
	RouterConnections routerConnections
	Security          security
}

Server store

func (*Server) Init

func (s *Server) Init()

Init method use to initialize related object with default data to prevent from panic!

func (*Server) Start

func (s *Server) Start() (err error)

Start will start the server.

type Service

type Service struct {
	ID                uint32 // Handy ID or Hash of name!
	Name              string
	IssueDate         int64
	ExpiryDate        int64
	ExpireInFavorOf   string // Other service name
	ExpireInFavorOfID uint32 // Other ServiceID! Handy ID or Hash of ExpireInFavorOf!
	Status            uint8
	Handler           PacketHandler
	Description       []string
	TAGS              []string
}

Service store needed data for service!

type TechnicalInfo

type TechnicalInfo struct {
	OS                   []string // PersiaOS, Linux, Windows, ...
	ApplicationProtocols []string // sRPC, HTTP, ...
	UseAI                bool     // false: Open the lot of security concerns || true: use more resource.
	AuthorizationServer  string   // Domain name that have sRPC needed store connection data. default is "apis.sabz.city"
	// Shutdown settings
	ShutdownDelay uint16 // the server will wait for at least this amount of time for active streams to finish!
	// Server Overal rate limit
	MaxOpenConnection uint64 // The maximum number of concurrent connections the app may serve.
	// Guest rete limit - Connection.OwnerType==0
	GuestMaxConnection            uint64 // 0 means App not accept guest connection.
	GuestMaxStreamConnectionDaily uint32 // Max open stream per day for a guest connection. overflow will drop on creation!
	GuestMaxServiceCallDaily      uint64 // 0 means no limit and good for PayAsGo strategy!
	GuestMaxBytesSendDaily        uint64
	GuestMaxBytesReceiveDaily     uint64
	GuestMaxPacketsSendDaily      uint64
	GuestMaxPacketsReceiveDaily   uint64
	// Registered rate limit - Connection.OwnerType==1
	RegisteredMaxConnection            uint64
	RegisteredMaxStreamConnectionDaily uint32 // Max open stream per day for a Registered user connection. overflow will drop on creation!
	RegisteredMaxServiceCallDaily      uint64 // 0 means no limit and good for PayAsGo strategy!
	RegisteredMaxBytesSendDaily        uint64
	RegisteredMaxBytesReceiveDaily     uint64
	RegisteredMaxPacketsSendDaily      uint64
	RegisteredMaxPacketsReceiveDaily   uint64
	// If you want to know Connection.OwnerType>1 rate limit strategy, You must read server codes!!
	//
	// Minimum hardware specification for each instance of application.
	CPU              uint64 // Hz
	RAM              uint64 // Byte
	GPU              uint64 // Hz
	NetworkBandwidth uint64 // Byte
	HDD              uint64 // Byte, Hard disk drive as storage engine. Act as object+block storage.
	SSD              uint64 // Byte, Solid state drive as storage engine. Act as object+block storage..
	// 4 type of devices trend now:
	// Out of XP scope - Cloud Computing - Cheapest scenario - Primary Datastore	::/1 ()
	// Adjacent Router or Inside same XP - Fog Computing - Caching Datastore		::/32
	// Inside Router scope - Edge Computing - Caching Datastore						::/64
	// End user device - 															::/128
	MaxNetworkScalability uint8 // If ::/32 it mean also ::/1 but not ::/64!!
}

TechnicalInfo store some technical information but may different from really server condition!

type UserConnection

type UserConnection struct {
	/* Connection data */
	UserConnectionID [16]byte
	UserGPID         uint32 // Part of GP that lease by OS delegate of a user!
	Status           uint8  // States locate in this file.
	Weight           uint8  // 16 queue for priority weight of the connections exist.
	MaxBandwidth     uint64 // Peer must respect this, otherwise connection will terminate and User go to black list!

	/* Peer data */
	Path            []byte // Chapar switch spec
	ReversePath     []byte // Chapar switch spec
	AlternativePath [][]byte
	ThingID         [16]byte
	UserID          [16]byte // Can't change after first set. 0 for Guest!
	UserType        uint8    // 0:Guest, 1:Registered 2:Person, 3:Org, 4:App, ...

	/* Security data */
	PeerPublicKey [32]byte
	Cipher        crypto.Cipher // Selected cipher algorithms https://en.wikipedia.org/wiki/Cipher_suite

	/* Metrics data */
	BytesSent             uint64 // Counts the bytes of payload data sent.
	PacketsSent           uint64 // Counts packets sent.
	BytesReceived         uint64 // Counts the bytes of payload data Receive.
	PacketsReceived       uint64 // Counts packets Receive.
	FailedPacketsReceived uint64 // Counts failed packets receive for firewalling server from some attack types!
}

UserConnection can use by any type users

Jump to

Keyboard shortcuts

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