core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressSize = 4
	DistMax     = 1<<15 - 1
)
View Source
const (
	BLANK = iota
	BLACK
	WHITE
)
View Source
const (
	EMPTY = iota
	PAWN
	KING
)
View Source
const (
	ALL = iota
	REPORT_BY_NAME
	REPORT_BY_DESCRIPTION
	REPORT_BY_ID
	REPORT_CATEGORIES
)
View Source
const (
	VERSION              = "0.0.1"
	MAX_MESSAGES_IN      = 1000
	MAX_MESSAGES_OUT     = 1000
	MAX_MESSAGE_HANDLERS = 100
	MAX_MESSAGE_SENDERS  = 100
	MAX_PEERS            = 50
	MAX_ACTIVE_PEERS     = 500
	MGMT_PORT            = 80
	SERVICE_PORT         = 33301
	DEFAULT_PORT         = 33400
	MIN_HOPS             = 7
	MAX_TTL              = 30
	BASE_DIR             = ".peer-z"
)
View Source
const (
	MAGIC_NUMBER = 0x0368
	RELAY_IP     = "delphi.local"
	RELAY_PORT   = 33200
)
View Source
const (
	STATE_OFF         = iota // peer unreachable
	STATE_INITIALIZED        // peer started
	STATE_READY              // peer ready to receive
	STATE_CONNECTED          // peer connected
	STATE_PR_SENT            // peer request sent
	STATE_PR_REFUSED         // peer request refused
	STATE_PR_WAIT            // peer request accepted
	STATE_PL_SENT            // peerlist sent
	STATE_PL_WAIT            // peerlist replied
	STATE_RP_SENT            // reroute protocol sent
	STATE_STANDBY            // waiting for connection confirmation
	STATE_RR_PENDING
)

Peer state

View Source
const (
	M_PING = iota
	M_ROUTING
	M_REROUTING
)
View Source
const (
	MSG_ACK_REQUEST = uint32(1) << iota
	MSG_ACK
	MSG_READ_REQUEST
	MSG_ROUTING_REQUEST
	MSG_TTL_EXPIRED
)
View Source
const (
	CMD_PR     = iota // peering request
	CMD_PR_ACK        // peering request acknowledgement
	CMD_PR_NAK        // peering requestrefusal
	CMD_PL            // peer list information
	CMD_PL_ACK        // peer listresponse
	CMD_RP            // re-routing proposal
	CMD_RP_ACK        // re-routing proposalacknowledgement
	CMD_RP_NAK        // re-routing proposalrefusal
	CMD_SR            // standby request
	CMD_SR_ACK        // standby request acknowledgement
	CMD_PR_OK         // confirm peering established
	CMD_RR            // Re-routing request
	CMD_RR_ACK        // Re-routing request acknowledgement
	CMD_RR_NAK        // Re-routing request refusal
	CMD_DR            // Disconnect request
	CMD_DR_ACK        // Disconnect request acknowledgement
)
View Source
const (
	SERVICE_NEW = 1 << iota
	SERVICE_RENAMED
	SERVICE_UPDATED
	SERVICE_ABANDONED
)
View Source
const (
	MSG_FMT_VERSION = 0x100
)
View Source
const (
	SVC_VERSION = 0x0100
)
View Source
const (
	TTL_EXPIRED = "Message TTL expired"
)

Variables

View Source
var (
	AddressNone      = Address{0}
	BroadcastAddress = Address{65535}
)
View Source
var Games []CKGame
View Source
var STATES = map[State]string{
	STATE_OFF:         "OFF",
	STATE_INITIALIZED: "Initialized",
	STATE_READY:       "Ready",
	STATE_CONNECTED:   "Connected",
	STATE_PR_SENT:     "PR Sent",
	STATE_PR_REFUSED:  "PR Refused",
	STATE_PR_WAIT:     "PR Wait",
	STATE_PL_SENT:     "PL Sent",
	STATE_PL_WAIT:     "PL Wait",
	STATE_RP_SENT:     "RP Sent",
	STATE_STANDBY:     "Standby",
	STATE_RR_PENDING:  "RR Pending",
}

Functions

func Abs

func Abs(x int16) int16

func Listen

func Listen()

Listen is handling connections from other peers

func Logf

func Logf(f string, v ...interface{})

func Logln

func Logln(v ...interface{})

func Loglnf

func Loglnf(f string, v ...interface{})

func OpenPort

func OpenPort(port uint16, portName string)

func RequestPeering

func RequestPeering(peer *Peer) error

RequestPeering Starts a peering request with peer

func SendJson

func SendJson(w http.ResponseWriter, data interface{}) error

func SendPage

func SendPage(w http.ResponseWriter, pageName string) error

func Start

func Start() error

Types

type Address

type Address [AddressSize]uint16

func (Address) Distance

func (address Address) Distance(address2 Address) Distance

func (Address) String

func (address Address) String() (value string)

type ApiDefinition

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

type ApiPeerInfo

type ApiPeerInfo struct {
	Name      string   `json:"name"`
	Address   string   `json:"address"`
	IP        string   `json:"ip"`
	LocalIP   string   `json:"localIp"`
	Port      int      `json:"port"`
	Distance  Distance `json:"distance"`
	PeerCount int      `json:"peers"`
}

type CKGame

type CKGame struct {
	gorm.Model
	Name    string   `json:"name"`
	Rows    int      `json:"rows"`
	Columns int      `json:"columns"`
	Color   int      `json:"color"`
	Moves   []CKMove `gorm:"foreignKey:GameID",json:"moves"`
}

type CKMove

type CKMove struct {
	gorm.Model
	Color     int          `json:"color"`
	Piece     int          `json:"piece"`
	Positions []CKPosition `gorm:"foreignKey:MoveID",json:"positions"`
	GameID    int
	Game      CKGame `json:"game"`
}

func (CKMove) MarshalJSON

func (move CKMove) MarshalJSON() ([]byte, error)

func (CKMove) String

func (move CKMove) String() (output string)

type CKPosition

type CKPosition struct {
	gorm.Model
	Row    int `json:"row"`
	Column int `json:"column"`
	Index  int `json:"play"`
	MoveID int
	Move   CKMove `json:"move"`
}

func (CKPosition) String

func (position CKPosition) String() string

type Content

type Content interface {
	Bytes() []byte
	String() string
}

type Directory

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

func (Directory) Deregister

func (directory Directory) Deregister(service Service) error

Abandon a service

func (*Directory) Register

func (directory *Directory) Register(service Service) error

Register a new service

func (Directory) Search

func (directory Directory) Search(serviceSearched Service) (report ServiceReport, count int)

func (Directory) SearchByDescription

func (directory Directory) SearchByDescription(description string) (services []*Service)

func (Directory) SearchByID

func (directory Directory) SearchByID(id int64) (*Service, error)

func (Directory) SearchByName

func (directory Directory) SearchByName(name string) (*Service, error)

type Distance

type Distance uint16

type Key

type Key interface{}

type Mail

type Mail struct {
	gorm.Model
	//From      Address    `gorm:"type:string;default:”"`
	//To        Address    `gorm:"type:string;default:”"`
	DateSent     time.Time `json:"dateSent"`
	DateReceived time.Time `json:"dateReceived"`
	DateRead     time.Time `json:"dateRead"`
	Subject      string    `json:"subject"`
	Body         string    `json:"body"`
	Flags        uint64    `json:"flags"`
	Mailboxes    []Mailbox `gorm:"many2many:mailbox_messages",json:"mailboxes"`
}

type Mailbox

type Mailbox struct {
	gorm.Model
	Name  string `json:"name"`
	Mails []Mail `gorm:"many2many:mailbox_messages",json:"messages"`
}

type Move

type Move CKMove

type MoveDesc

type MoveDesc struct {
	Move Move   `json:"move"`
	Desc string `json:"desc"`
}

type Peer

type Peer struct {
	gorm.Model
	// contains filtered or unexported fields
}
var Me *Peer

func NewPeer

func NewPeer(name string, address Address, ip string, port int) *Peer

func (*Peer) Address

func (peer *Peer) Address() Address

return peer address

func (*Peer) CheckList

func (peer *Peer) CheckList(peer2 *Peer) RerouteList

func (Peer) Distance

func (peer Peer) Distance(peer2 Peer) Distance

func (Peer) GetList

func (peer Peer) GetList() Peers

func (Peer) Info

func (peer Peer) Info() (info PeerInfo)

func (*Peer) Ip

func (peer *Peer) Ip() string

Return IP used by peer

func (Peer) MarshalPeerData

func (peer Peer) MarshalPeerData(writer io.Writer, message peerMessage) error

func (*Peer) Name

func (peer *Peer) Name() string

Return peer name

func (*Peer) Port

func (peer *Peer) Port() int

Return port used by peer

func (*Peer) PortString

func (peer *Peer) PortString() string

Return string representation of peer port

func (*Peer) SetAddress

func (peer *Peer) SetAddress(address Address) *Peer

Update peer address

func (*Peer) SetIp

func (peer *Peer) SetIp(ip string) *Peer

func (*Peer) SetName

func (peer *Peer) SetName(name string) *Peer

Set peer name

func (*Peer) SetPort

func (peer *Peer) SetPort(port int) *Peer

Update peer port

func (*Peer) SetState

func (peer *Peer) SetState(state State) *Peer

Set peer state

func (*Peer) SetStateInfo

func (peer *Peer) SetStateInfo(info string) *Peer

Set peer stateInfo

func (*Peer) State

func (peer *Peer) State() State

Return peer state

func (Peer) String

func (peer Peer) String() string

type PeerInfo

type PeerInfo struct {
	Name      string   `json:"name"`
	Address   Address  `json:"address"`
	IP        string   `json:"ip"`
	LocalIp   string   `json:"localIp"`
	Port      int      `json:"port"`
	Distance  Distance `json:"distance"`
	PeerCount int      `json:"peers"`
}

func UnmarshalPeerData

func UnmarshalPeerData(reader io.Reader) (*peerMessage, *PeerInfo, error)

func (PeerInfo) ApiInfo

func (peerInfo PeerInfo) ApiInfo() ApiPeerInfo

func (PeerInfo) Peer

func (info PeerInfo) Peer() (peer Peer)

func (PeerInfo) String

func (peerInfo PeerInfo) String() string

type PeerInfos

type PeerInfos []PeerInfo

func (PeerInfos) ApiPeerInfos

func (infos PeerInfos) ApiPeerInfos() (apiPeerInfos []ApiPeerInfo)

func (PeerInfos) Bytes

func (peerInfos PeerInfos) Bytes() []byte

func (PeerInfos) Peers

func (peerInfos PeerInfos) Peers() (peers Peers)

func (PeerInfos) String

func (peerInfos PeerInfos) String() (output string)

type PeerInfosByZero

type PeerInfosByZero PeerInfos

func (PeerInfosByZero) Len

func (peerInfos PeerInfosByZero) Len() int

func (PeerInfosByZero) Less

func (peerInfos PeerInfosByZero) Less(i, j int) bool

func (PeerInfosByZero) Swap

func (peerInfos PeerInfosByZero) Swap(i, j int)

type PeerList

type PeerList Peers

type Peers

type Peers []Peer

func GeneratePeers

func GeneratePeers() Peers

GetPeers is used to obtain an initial list of peers

func (Peers) Bytes

func (peers Peers) Bytes() []byte

func (Peers) Filter

func (peers Peers) Filter(address Address) (filteredPeers Peers)

func (Peers) FilterMe

func (peers Peers) FilterMe() (filteredPeers Peers)

func (Peers) Info

func (peers Peers) Info() (infos PeerInfos)

func (Peers) String

func (peers Peers) String() (output string)

type PeersByAddress

type PeersByAddress Peers

func (PeersByAddress) Len

func (peers PeersByAddress) Len() int

func (PeersByAddress) Less

func (peers PeersByAddress) Less(i int, j int) bool

func (PeersByAddress) Swap

func (peers PeersByAddress) Swap(i, j int)

type PeersByDistance

type PeersByDistance Peers

func (PeersByDistance) Len

func (peers PeersByDistance) Len() int

func (PeersByDistance) Less

func (peers PeersByDistance) Less(i, j int) bool

func (PeersByDistance) Swap

func (peers PeersByDistance) Swap(i, j int)

type PeersByName

type PeersByName Peers

func (PeersByName) Len

func (peers PeersByName) Len() int

func (PeersByName) Less

func (peers PeersByName) Less(i, j int) bool

func (PeersByName) Swap

func (peers PeersByName) Swap(i, j int)

type RerouteList

type RerouteList struct {
	Gimme PeerInfos
	Get   PeerInfos
}

func (RerouteList) Bytes

func (rerouteList RerouteList) Bytes() []byte

func (RerouteList) String

func (rerouteList RerouteList) String() string

type Route

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

type Service

type Service struct {
	Info ServiceInfo `json:"info"`
	// contains filtered or unexported fields
}

func (Service) StartService

func (service Service) StartService()

type ServiceHandlers

type ServiceHandlers []ApiDefinition

func (*ServiceHandlers) AddHandler

func (serviceHandlers *ServiceHandlers) AddHandler(definition ApiDefinition)

type ServiceInfo

type ServiceInfo struct {
	Id          int64  `json:"id"`
	Version     uint16 `json:"version"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Port        int    `json:"port"`
	// contains filtered or unexported fields
}

type ServiceReport

type ServiceReport [REPORT_CATEGORIES][]*Service

type ServiceStarter

type ServiceStarter interface {
	StartService()
}

type State

type State int

func (State) String

func (state State) String() string

type Storage

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

type StorageBlock

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

type StoredData

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

func (StoredData) AddBlock

func (storageData StoredData) AddBlock(block StorageBlock)

func (StoredData) Search

func (storageData StoredData) Search(name string) (*StorageBlock, error)

Jump to

Keyboard shortcuts

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