p2pserver

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PP_LOG_ALL      = false
	PP_LOG_READ     = true
	PP_LOG_WRITE    = true
	PP_LOG_INBOUND  = true
	PP_LOG_OUTBOUND = true

	LAST_RECONNECT_KEY               = "last_reconnect"
	MIN_RECONNECT_INTERVAL_THRESHOLD = 60  // seconds
	MAX_RECONNECT_INTERVAL_THRESHOLD = 600 // seconds
	RECONNECT_INTERVAL_MULTIPLIER    = 2
)

Variables

This section is empty.

Functions

func CreateNewContextPacketId

func CreateNewContextPacketId(ctx context.Context) (int64, context.Context)

CreateNewContextPacketId used for downloading / uploading speed tracking

Types

type LastReconnectRecord

type LastReconnectRecord struct {
	SpP2PAddress                string
	Time                        time.Time
	NextAllowableReconnectInSec int64
}

type P2pServer

type P2pServer struct {

	// SPMaintenanceMap stores records of SpUnderMaintenance, K - SpP2pAddress, V - list of MaintenanceRecord
	SPMaintenanceMap *utils.AutoCleanMap
	// contains filtered or unexported fields
}

func GetP2pServer

func GetP2pServer(ctx context.Context) *P2pServer

func (*P2pServer) AddConnConntextKey

func (p *P2pServer) AddConnConntextKey(key interface{})

func (*P2pServer) CleanUpConnMap

func (p *P2pServer) CleanUpConnMap(fileHash string)

func (*P2pServer) ClearBufferedSpConns

func (p *P2pServer) ClearBufferedSpConns()

func (*P2pServer) ConfirmOptSP

func (p *P2pServer) ConfirmOptSP(ctx context.Context, spNetworkAddr string)

ConfirmOptSP connect if there is a detected optimal SP node.

func (*P2pServer) ConnectToSP

func (p *P2pServer) ConnectToSP(ctx context.Context) (newConnection bool, err error)

ConnectToSP Checks if there is a connection to an SP node. If it doesn't, it attempts to create one with a random SP node.

func (*P2pServer) DeleteConnFromCache

func (p *P2pServer) DeleteConnFromCache(key string)

DeleteConnFromCache access function for member cachedConnMap

func (*P2pServer) DeletePPByNetworkAddress

func (p *P2pServer) DeletePPByNetworkAddress(ctx context.Context, p2pAddr string)

DeletePPByNetworkAddress

func (*P2pServer) GetBufferedSpConns

func (p *P2pServer) GetBufferedSpConns() []*cf.ClientConn

func (*P2pServer) GetClientConn

func (p *P2pServer) GetClientConn(networkAddr string) (*cf.ClientConn, bool)

func (*P2pServer) GetConnectionName

func (p *P2pServer) GetConnectionName(conn core.WriteCloser) string

func (*P2pServer) GetP2PAddrInTypeAddress added in v0.10.0

func (p *P2pServer) GetP2PAddrInTypeAddress() utilstypes.Address

func (*P2pServer) GetP2PAddress added in v0.10.0

func (p *P2pServer) GetP2PAddress() string

func (*P2pServer) GetP2PPublicKey added in v0.10.0

func (p *P2pServer) GetP2PPublicKey() []byte

func (*P2pServer) GetP2pServer

func (p *P2pServer) GetP2pServer() *core.Server

func (*P2pServer) GetPPByP2pAddress

func (p *P2pServer) GetPPByP2pAddress(ctx context.Context, p2pAddr string) *types.PeerInfo

GetPPByP2pAddress

func (*P2pServer) GetPPInfo added in v0.10.0

func (p *P2pServer) GetPPInfo() *protos.PPBaseInfo

func (*P2pServer) GetPPList

func (p *P2pServer) GetPPList(ctx context.Context) (list []*types.PeerInfo, total int64, connected int64)

GetPPList

func (*P2pServer) GetPpConn

func (p *P2pServer) GetPpConn() *cf.ClientConn

func (*P2pServer) GetSpConn

func (p *P2pServer) GetSpConn() *cf.ClientConn

func (*P2pServer) GetSpName

func (p *P2pServer) GetSpName() string

func (*P2pServer) Init added in v0.10.0

func (p *P2pServer) Init() error

func (*P2pServer) LoadConnFromCache

func (p *P2pServer) LoadConnFromCache(key string) (*cf.ClientConn, bool)

LoadConnFromCache access function for member cachedConnMap

func (*P2pServer) LoadRequestInfo added in v0.10.0

func (p *P2pServer) LoadRequestInfo(reqId int64, rspMsgType uint8) (uint8, bool)

func (*P2pServer) NewClientToAlternativeSp

func (p *P2pServer) NewClientToAlternativeSp(ctx context.Context, server string) (*cf.ClientConn, error)

func (*P2pServer) NewClientToMainSp

func (p *P2pServer) NewClientToMainSp(ctx context.Context, server string) error

func (*P2pServer) NewClientToPp

func (p *P2pServer) NewClientToPp(ctx context.Context, server string, heartbeat bool) (*cf.ClientConn, error)

func (*P2pServer) PPDisconnected

func (p *P2pServer) PPDisconnected(ctx context.Context, p2pAddress, networkAddress string)

func (*P2pServer) PPDisconnectedNetId

func (p *P2pServer) PPDisconnectedNetId(ctx context.Context, netId int64)

func (*P2pServer) RangeCachedConn

func (p *P2pServer) RangeCachedConn(prefix string, rf func(k, v interface{}) bool)

func (*P2pServer) ReadOfflineChan

func (p *P2pServer) ReadOfflineChan() chan *offline

func (*P2pServer) RecordSpMaintenance

func (p *P2pServer) RecordSpMaintenance(spP2pAddress string, recordTime time.Time) bool

RecordSpMaintenance return boolean flag of switching to new SP

func (*P2pServer) ReqTransferSendSP

func (p *P2pServer) ReqTransferSendSP(ctx context.Context, conn core.WriteCloser)

func (*P2pServer) SavePPList

func (p *P2pServer) SavePPList(ctx context.Context, target *protos.RspGetPPList) error

SavePPList will save the target list to local list

func (*P2pServer) SendMessage

func (p *P2pServer) SendMessage(ctx context.Context, conn core.WriteCloser, pb proto.Message, cmd header.MsgType) error

func (*P2pServer) SendMessageByCachedConn

func (p *P2pServer) SendMessageByCachedConn(ctx context.Context, key string, netAddr string, pb proto.Message, cmd header.MsgType, fn core.WriteHookFunc) error

func (*P2pServer) SendMessageDirectToSPOrViaPP

func (p *P2pServer) SendMessageDirectToSPOrViaPP(ctx context.Context, pb proto.Message, cmd header.MsgType)

func (*P2pServer) SendMessageToSPServer

func (p *P2pServer) SendMessageToSPServer(ctx context.Context, pb proto.Message, cmd header.MsgType)

func (*P2pServer) SetPPServer

func (p *P2pServer) SetPPServer(pp *core.Server)

func (*P2pServer) SetPpClientConn

func (p *P2pServer) SetPpClientConn(ppConn *cf.ClientConn)

func (*P2pServer) SignP2pMessage added in v0.10.0

func (p *P2pServer) SignP2pMessage(signMsg []byte) []byte

func (*P2pServer) SpConnValid

func (p *P2pServer) SpConnValid() bool

func (*P2pServer) Start

func (p *P2pServer) Start(ctx context.Context)

func (*P2pServer) StartListenServer

func (p *P2pServer) StartListenServer(ctx context.Context, port string)

func (*P2pServer) Stop

func (p *P2pServer) Stop()

func (*P2pServer) StoreBufferedSpConn

func (p *P2pServer) StoreBufferedSpConn(spConn *cf.ClientConn)

func (*P2pServer) StoreConnToCache

func (p *P2pServer) StoreConnToCache(key string, conn *cf.ClientConn)

StoreConnToCache access function for member cachedConnMap

func (*P2pServer) StoreRequestInfo added in v0.10.0

func (p *P2pServer) StoreRequestInfo(reqId int64, reqMsgType uint8)

func (*P2pServer) TransferSendMessageToClient

func (p *P2pServer) TransferSendMessageToClient(ctx context.Context, p2pAddress string, msgBuf *msg.RelayMsgBuf)

func (*P2pServer) TransferSendMessageToPPServ

func (p *P2pServer) TransferSendMessageToPPServ(ctx context.Context, addr string, msgBuf *msg.RelayMsgBuf) error

func (*P2pServer) TransferSendMessageToPPServByP2pAddress

func (p *P2pServer) TransferSendMessageToPPServByP2pAddress(ctx context.Context, p2pAddress string, msgBuf *msg.RelayMsgBuf)

func (*P2pServer) TransferSendMessageToSPServer

func (p *P2pServer) TransferSendMessageToSPServer(ctx context.Context, message *msg.RelayMsgBuf)

func (*P2pServer) UpdatePP

func (p *P2pServer) UpdatePP(ctx context.Context, pp *types.PeerInfo)

UpdatePP will update one pp info to local list

Jump to

Keyboard shortcuts

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