epsp

package module
v0.0.0-...-baa7262 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: BSD-3-Clause Imports: 29 Imported by: 0

README

go-epsp

Build Status GoDoc Go Report Card

Golang library for EPSP protocol.

EPSP protocol is shown in https://p2pquake.github.io/epsp-specifications/epsp-specifications.html

This library implements EPSP protocol. Need golang 1.9 or later because sync.Map is used.

If you want to run on P2PQuake network ( https://www.p2pquake.net/ )

% cd %GOPATH%\src\github.com\toyo\epsp\cmd\p2pquake (Win)

% cd $GOPATH/src/github.com/toyo/epsp/cmd/p2pquake (Unix)

% go get github.com/toyo/epsp/cmd/p2pquake

% %GOPATH%/bin/p2pquake -d (Win)

% $GOPATH/bin/p2pquake -d (Unix)

or

% docker run -Pit toyokun/p2pquake

At the machine which this program runs, you can see EPSP statistics at http://localhost:6980/ or http://[dockerip]:6980/

This main.go doesn't support to send "地震感知情報" (555). To send this, use peer.WriteExceptFrom() function with from = null.

I welcome your PR.

Thanks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Area

func Area(regioncode string) (region string)

Area は、地域コードを地域名に変換します

func AreaForRegLatLng

func AreaForRegLatLng(regioncode string) (region []string)

AreaForRegLatLng は、地域コードを地域名緯度経度に変換します

func DataSignatureCheck

func DataSignatureCheck(key *rsa.PublicKey, dataSig, expDate, dataBody string) error

DataSignatureCheck は、データ署名を照合します

func DecryptKey

func DecryptKey(key []byte) (*rsa.PublicKey, error)

DecryptKey は、鍵を復号します

func KeySignatureCheck

func KeySignatureCheck(key *rsa.PublicKey, pubKey, keySig, keyExpDate string) (*rsa.PublicKey, error)

KeySignatureCheck は、鍵署名を照合します

func SetLogger

func SetLogger(l *log.Logger)

SetLogger は、ロガーを設定します

func SetLoggerDebug

func SetLoggerDebug()

SetLoggerDebug は、ロガーをデバッグモードにします

Types

type EPSPConn

type EPSPConn struct {
	IPPort       string
	ConnTime     *time.Time
	PingTime     *time.Time
	PongTime     *time.Time
	PingPong     *time.Duration
	PingRecvTime *time.Time
	DiscTime     *time.Time
	LastRXTime   *time.Time
	Agent        []string

	Tx     uint64
	Rx     uint64
	RxUniq uint64
	RxDup  uint64
	// contains filtered or unexported fields
}

EPSPConn は、EPSPの接続情報を保持します

func (*EPSPConn) AddRx

func (p *EPSPConn) AddRx()

AddRx はRxを一つ増やします

func (*EPSPConn) AddRxDup

func (p *EPSPConn) AddRxDup()

AddRxDup はRxDupを一つ増やします

func (*EPSPConn) AddRxUniq

func (p *EPSPConn) AddRxUniq()

AddRxUniq はRxUniqを一つ増やします

func (*EPSPConn) AddTx

func (p *EPSPConn) AddTx()

AddTx はTxを一つ増やします

func (*EPSPConn) Close

func (p *EPSPConn) Close()

Close はTCPを終了します

func (*EPSPConn) Get

func (p *EPSPConn) Get(ctx context.Context) (string, error)

Get は、データを一行取得し、文字列を返します

func (*EPSPConn) GetConnTime

func (p *EPSPConn) GetConnTime() *time.Time

GetConnTime は、接続した時刻を取得します

func (*EPSPConn) GetDiscTime

func (p *EPSPConn) GetDiscTime() *time.Time

GetDiscTime は、Pingした時刻を取得します

func (*EPSPConn) GetPingRecv

func (p *EPSPConn) GetPingRecv() *time.Time

GetPingRecv は、Pingを受信した時刻を取得します

func (*EPSPConn) GetPingTime

func (p *EPSPConn) GetPingTime() *time.Time

GetPingTime は、Pingした時刻を取得します

func (*EPSPConn) GetRXUniqRate

func (p *EPSPConn) GetRXUniqRate() uint64

GetRXUniqRate はすべての受信情報のうち、最速だったものの割合の逆数を返します

func (*EPSPConn) IsConn

func (p *EPSPConn) IsConn() bool

IsConn は、接続中かどうか返します

func (*EPSPConn) SetConnTime

func (p *EPSPConn) SetConnTime()

SetConnTime は、現在時刻を接続時間として設定します

func (*EPSPConn) SetDiscTime

func (p *EPSPConn) SetDiscTime()

SetDiscTime は、現在時刻を切断時間として設定します

func (*EPSPConn) SetLastRXTime

func (p *EPSPConn) SetLastRXTime()

SetLastRXTime は、最後にデータを受信した時刻を設定します

func (*EPSPConn) SetPingRecvTime

func (p *EPSPConn) SetPingRecvTime()

SetPingRecvTime は、現在時刻をPingを受け取った時刻として設定します

func (*EPSPConn) SetPingTime

func (p *EPSPConn) SetPingTime()

SetPingTime は、現在時刻をPingした時刻として設定します

func (*EPSPConn) SetPongTime

func (p *EPSPConn) SetPongTime()

SetPongTime は、現在時刻をPingの返答を受け取った時刻として設定します

func (*EPSPConn) Write

func (p *EPSPConn) Write(strs ...string) error

type P2PPeer

type P2PPeer struct {
	PeerID string
	EPSPConn
}

P2PPeer は、ピア接続のためのクラスです

func NewP2PClient

func NewP2PClient(ctx context.Context, ipportpeerid string, connectedIPPortPeersList func() []string) (pc *P2PPeer, err error)

NewP2PClient は、他のピアと接続します。

func NewP2PServer

func NewP2PServer(ctx context.Context, l *traditionalnet.TCPListener, myagent []string) (ps *P2PPeer, err error)

NewP2PServer は、ピアからの接続を待ちます

func (*P2PPeer) Close

func (p *P2PPeer) Close()

Close は、ピア接続を終了します

func (*P2PPeer) GetIPPortPeerID

func (p *P2PPeer) GetIPPortPeerID() string

GetIPPortPeerID は、IP,Port,PeerID 形式の文字列を返します

func (*P2PPeer) GetPeerID

func (p *P2PPeer) GetPeerID() string

GetPeerID は、PeerIDを取得します

func (*P2PPeer) GetPeerIDorIPPort

func (p *P2PPeer) GetPeerIDorIPPort() string

GetPeerIDorIPPort は、PeerID、IPアドレス、ポートを取得します

func (*P2PPeer) NetLoop

func (p *P2PPeer) NetLoop(ctx context.Context, mypeerid string, agent []string, peers func() []string, codep2mp func(peer *P2PPeer, retval []string) (err error)) (err error)

NetLoop は、接続済みTCP接続からデータの読み書きします

func (P2PPeer) StringAgent

func (p P2PPeer) StringAgent() string

StringAgent は、エージェント名の文字列を返します

func (*P2PPeer) WriteTo

func (p *P2PPeer) WriteTo(ss ...string) (err error)

WriteTo は、peeridへssを送信します

type P2PPeers

type P2PPeers []*P2PPeer

P2PPeers is array of *P2PPeer

func (*P2PPeers) AddP2PClients

func (pps *P2PPeers) AddP2PClients(ctx context.Context, mypeerid string, otherPeers []string, myagent []string, codep2mp func(from *P2PPeer, retval []string) error, ConnectedIPPortPeersList func() []string, incoming uint64)

AddP2PClients は、P2PClientsを追加します

func (*P2PPeers) ConnectedIPPortPeersList

func (pps *P2PPeers) ConnectedIPPortPeersList() (ss []string)

ConnectedIPPortPeersList は、接続中ピアのIPアドレス,ポート,ピアIDのリストを返します

func (*P2PPeers) ConnectedPeersList

func (pps *P2PPeers) ConnectedPeersList() (ss []string)

ConnectedPeersList は、接続中ピアのピアIDのリストを返します

func (*P2PPeers) NewP2PServers

func (pps *P2PPeers) NewP2PServers(ctx context.Context, mypeerid string, myagent []string, port int, codep2mp func(from *P2PPeer, retval []string) error, ConnectedIPPortPeersList func() []string, incoming uint64) (global bool, err error)

NewP2PServers は、P2PServerを立ち上げます

func (*P2PPeers) NumOfConnectedPeers

func (pps *P2PPeers) NumOfConnectedPeers() (n uint64)

NumOfConnectedPeers は、接続中ピアの数を返します

type P2SClient

type P2SClient struct {
	EPSPConn
}

P2SClient は、サーバに対するクライアントです

func NewP2SClient

func NewP2SClient(ctx context.Context, paddr string, myagent0 []string) (p2s *P2SClient, myagent []string, err error)

NewP2SClient は、サーバ接続用のクライアントです

func (P2SClient) CheckPortOpen

func (p2s P2SClient) CheckPortOpen(ctx context.Context, peerID string, peercount int) (open bool, err error)

CheckPortOpen は、ポート開放をサーバに確認します

func (*P2SClient) Close

func (p2s *P2SClient) Close(ctx context.Context)

Close は、サーバとの接続を終了します

func (*P2SClient) Echo

func (p2s *P2SClient) Echo(ctx context.Context, peerID string, peercount uint64) (err error)

Echo は、エコーを送信し、返信を受け取ります

func (P2SClient) GetKey

func (p2s P2SClient) GetKey(ctx context.Context, peer *Peer, echo bool) (err error)

GetKey は、キーを取得します

func (P2SClient) GetPeerID

func (p2s P2SClient) GetPeerID() string

GetPeerID は、相手のPeerIDを返すものですが、サーバにはPeerIDがないので、IPとポートを返します。

func (P2SClient) GetPeers

func (p2s P2SClient) GetPeers(ctx context.Context, peerID string) (peers []string, err error)

GetPeers は、サーバから接続可能なピア情報を取得します

func (P2SClient) GetTemporaryPeerID

func (p2s P2SClient) GetTemporaryPeerID(ctx context.Context) (peerID string, err error)

GetTemporaryPeerID は、サーバから暫定ピアIDを取得します

func (P2SClient) GetTime

func (p2s P2SClient) GetTime(ctx context.Context) (t time.Time, err error)

GetTime は、プロトコル時刻を取得します

func (P2SClient) PeerCountByRegion

func (p2s P2SClient) PeerCountByRegion(ctx context.Context, code5xx func(from *P2PPeer, retval []string) error) (peerCountByName PeerCounts, err error)

PeerCountByRegion は、地域ごとのピア数を取得します

func (P2SClient) Regist

func (p2s P2SClient) Regist(ctx context.Context, peerID string, port int, region string, numofpeers uint64, incoming uint64) (err error)

Regist は、ピアIDの本割り当てを要求します

func (P2SClient) TellPeer

func (p2s P2SClient) TellPeer(ps P2PPeers, limited []string) (err error)

TellPeer は、ピアとの接続状況を、サーバに伝えます

type Peer

type Peer struct {
	PeerID           string
	BootTime         time.Time
	ProtocolTimeDiff time.Duration
	MyAgent          []string
	EPSPServer       *P2SClient
	Clients          P2PPeers
	Servers          P2PPeers

	PeerCountsByRegion PeerCounts

	Global bool
	// contains filtered or unexported fields
}

Peer はピアに関するデータを保持します。

func NewPeer

func NewPeer(hosts []string, region string, incoming uint64, serverKey, peerKey []byte, usercmd func(code string, retval ...string)) (*Peer, error)

NewPeer は、Peerのコンストラクタです

func (*Peer) ConnectedIPPortPeersList

func (peer *Peer) ConnectedIPPortPeersList() (ss []string)

ConnectedIPPortPeersList は、接続中ピアのIPアドレス,ポート,ピアIDのリストを返します

func (*Peer) ConnectedPeersList

func (peer *Peer) ConnectedPeersList() (ss []string)

ConnectedPeersList は、接続中ピアのリストを返します

func (*Peer) LoadKey

func (peer *Peer) LoadKey() (peers []string, err error)

LoadKey は、キーをロードするメソッドです。

func (*Peer) Loop

func (peer *Peer) Loop(ctx context.Context, port int) (err error)

Loop は、EPSPサーバと定期的な接続を行うことで、ピアとの接続を維持するメソッドです。

func (*Peer) NumOfConnectedPeers

func (peer *Peer) NumOfConnectedPeers() (n uint64)

NumOfConnectedPeers は、接続中ピアの数を返します

func (*Peer) PeerIDToP2PPeer

func (peer *Peer) PeerIDToP2PPeer(peerid string) *P2PPeer

PeerIDToP2PPeer は、peeridに対応するP2PPeerを返します。対応するP2PPeerがなければnilを返します。

func (*Peer) SaveKey

func (peer *Peer) SaveKey()

SaveKey は、キーをセーブするメソッドです。

func (*Peer) WebSocketAPI

func (peer *Peer) WebSocketAPI(ctx context.Context, hs *http.ServeMux)

WebSocketAPI is handler for websocket api.

func (*Peer) WriteExceptFrom

func (peer *Peer) WriteExceptFrom(from *P2PPeer, ss ...string)

WriteExceptFrom は、from以外へssを送信します

type PeerCounts

type PeerCounts []peerCount

PeerCounts is count of region

func NewPeerCount

func NewPeerCount(recvdata2 string) (peerCountByRegion PeerCounts)

NewPeerCount is constructor of PeerCount

func (PeerCounts) GoogleChart

func (p PeerCounts) GoogleChart() []byte

GoogleChart makes GoogleChart JSON table.

func (PeerCounts) NumOfAllPeers

func (p PeerCounts) NumOfAllPeers() (numOfAPeers uint64)

NumOfAllPeers は、すべてのPeer数の合計です

func (PeerCounts) String

func (p PeerCounts) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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