p2p

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: LGPL-2.1 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationChannel string = "ml-authorization-channel"
	TopicChannel         string = "ml-topic-channel"
	SubnetChannel        string = "ml-sub-network-channel"
	WalletChannel        string = "ml-wallet-channel"
	MessageChannel       string = "ml-message-channel"
	SubscriptionChannel         = "ml-subscription-channel"
	// UnSubscribeChannel                = "ml-unsubscribe-channel"
	// ApproveSubscriptionChannel        = "ml-approve-subscription-channel"
	BatchChannel         = "ml-batch-channel"
	DeliveryProofChannel = "ml-delivery-proof"
)

Variables

View Source
var Delimiter = []byte{'0'}
View Source
var DisconnectFromPeer = make(map[peer.ID]bool)
View Source
var Host host.Host
View Source
var MainContext *context.Context
View Source
var PeerPubKeys = make(map[peer.ID][]byte)

var PeerStreams = make(map[string]peer.ID)

Functions

func GetAndSaveMessageCostFromChain added in v1.2.0

func GetAndSaveMessageCostFromChain(ctx *context.Context, cycle uint64) (*big.Int, error)

func GetCycleMessageCost added in v1.2.0

func GetCycleMessageCost(ctx context.Context, cycle uint64) (*big.Int, error)
	if md.IsValid(chainId) {
		return multiaddr.NewMultiaddr(md.Addresses[0])
	}
	return nil, fmt.Errorf("invalid multiaddress ")
}

check the dht before going onchain

func GetDhtValue added in v1.2.0

func GetDhtValue(key string) ([]byte, error)

func GetMultiAddresses added in v1.2.0

func GetMultiAddresses(h host.Host) []string

func GetNodeAddress added in v1.2.0

func GetNodeAddress(ctx *context.Context, pubKey string) (multiaddr.Multiaddr, error)

func ProcessEventsReceivedFromOtherNodes

func ProcessEventsReceivedFromOtherNodes(modelType entities.EntityModel, fromPubSubChannel *entities.Channel, mainCtx *context.Context, process func(event *entities.Event, ctx *context.Context))

func Run

func Run(mainCtx *context.Context)

Types

type DhtValidator added in v1.2.0

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

func (*DhtValidator) Select added in v1.2.0

func (v *DhtValidator) Select(key string, values [][]byte) (int, error)

func (*DhtValidator) Validate added in v1.2.0

func (v *DhtValidator) Validate(key string, value []byte) error

type IState added in v1.2.0

type IState interface {
	MsgPack() []byte
}

type MessagePrice added in v1.2.0

type MessagePrice struct {
	Cycle     json.RawMessage `json:"cy"`
	ChainId   configs.ChainId `json:"pre"`
	Price     json.RawMessage `json:"pr"`
	Signature json.RawMessage `json:"sig"`
	Signer    string          `json:"sign"`
	Timestamp uint64          `json:"ts"`
	// contains filtered or unexported fields
}

func NewMessagePrice added in v1.2.0

func NewMessagePrice(config *configs.MainConfiguration, privateKey []byte, price []byte, cycle []byte) (*MessagePrice, error)

func UnpackMessagePrice added in v1.2.0

func UnpackMessagePrice(b []byte) (MessagePrice, error)

func (MessagePrice) EncodeBytes added in v1.2.0

func (mp MessagePrice) EncodeBytes() ([]byte, error)

func (*MessagePrice) IsValid added in v1.2.0

func (mp *MessagePrice) IsValid(prefix configs.ChainId) bool

func (*MessagePrice) MsgPack added in v1.2.0

func (mp *MessagePrice) MsgPack() []byte

type NetworkGater added in v1.2.0

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

func (*NetworkGater) InterceptAccept added in v1.2.0

func (g *NetworkGater) InterceptAccept(network.ConnMultiaddrs) (allow bool)

InterceptAccept checks if an incoming connection should be allowed

func (*NetworkGater) InterceptAddrDial added in v1.2.0

func (g *NetworkGater) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool)

InterceptAddrDial checks if a dial to a multiaddr should be allowed

func (*NetworkGater) InterceptPeerDial added in v1.2.0

func (g *NetworkGater) InterceptPeerDial(p peer.ID) (allow bool)

InterceptPeerDial checks if a peer dial should be allowed

func (*NetworkGater) InterceptSecured added in v1.2.0

func (g *NetworkGater) InterceptSecured(dir network.Direction, p peer.ID, addrs network.ConnMultiaddrs) (allow bool)

InterceptSecured checks if a secured connection should be allowed

func (*NetworkGater) InterceptUpgraded added in v1.2.0

func (g *NetworkGater) InterceptUpgraded(network.Conn) (allow bool, reason string)

InterceptUpgraded checks if an upgraded connection should be allowed

type NodeHandshake added in v1.2.0

type NodeHandshake struct {
	Timestamp uint64             `json:"ts"`
	Protocol  string             `json:"pro"`
	ChainId   configs.ChainId    `json:"pre"`
	NodeType  constants.NodeType `json:"nT"`
	Salt      string             `json:"salt"`
	Signature json.RawMessage    `json:"s"`
	Signer    string             `json:"sigr"`
	Synced    bool               `json:"synced"`
	// contains filtered or unexported fields
}

func NewNodeHandshake added in v1.2.0

func NewNodeHandshake(config *configs.MainConfiguration, protocolId string, privateKey []byte, nodeType constants.NodeType) (*NodeHandshake, error)

func NodeHandshakeFromJSON added in v1.2.0

func NodeHandshakeFromJSON(json string) (NodeHandshake, error)

func UnpackNodeHandshake added in v1.2.0

func UnpackNodeHandshake(b []byte) (NodeHandshake, error)

func (NodeHandshake) EncodeBytes added in v1.2.0

func (hsd NodeHandshake) EncodeBytes() ([]byte, error)

func (*NodeHandshake) Init added in v1.2.0

func (hs *NodeHandshake) Init(jsonString string) error

func (*NodeHandshake) IsValid added in v1.2.0

func (handshake *NodeHandshake) IsValid(chainId configs.ChainId) bool

func (*NodeHandshake) MsgPack added in v1.2.0

func (hs *NodeHandshake) MsgPack() []byte

func (*NodeHandshake) ToJSON added in v1.2.0

func (hs *NodeHandshake) ToJSON() []byte

type NodeMultiAddressData added in v1.2.0

type NodeMultiAddressData struct {
	Addresses []string        `json:"addr"`
	Timestamp uint64          `json:"ts"`
	ChainId   configs.ChainId `json:"pre"`
	Signer    json.RawMessage `json:"signr"`
	PubKeyEDD json.RawMessage `json:"pubKey"`
	Signature json.RawMessage `json:"sig"`
	// contains filtered or unexported fields
}

func GetNodeMultiAddressData added in v1.2.0

func GetNodeMultiAddressData(ctx *context.Context, key string) (*NodeMultiAddressData, error)

func NewNodeMultiAddressData added in v1.2.0

func NewNodeMultiAddressData(config *configs.MainConfiguration, privateKey []byte, addresses []string, pubKeyEDD []byte) (*NodeMultiAddressData, error)

func UnpackNodeMultiAddressData added in v1.2.0

func UnpackNodeMultiAddressData(b []byte) (NodeMultiAddressData, error)

func (NodeMultiAddressData) EncodeBytes added in v1.2.0

func (n NodeMultiAddressData) EncodeBytes() ([]byte, error)

func (*NodeMultiAddressData) IsValid added in v1.2.0

func (nma *NodeMultiAddressData) IsValid(prefix configs.ChainId) bool

func (*NodeMultiAddressData) MsgPack added in v1.2.0

func (hs *NodeMultiAddressData) MsgPack() []byte

type NodeMultiAddressDataIndexed added in v1.2.0

type NodeMultiAddressDataIndexed struct {
	Index int
	Data  NodeMultiAddressData
}

type P2pAction added in v1.2.0

type P2pAction int8
const (
	P2pActionResponse       P2pAction = 0
	P2pActionGetEvent       P2pAction = 1
	P2pActionGetCommitment  P2pAction = 2
	P2pActionGetSentryProof P2pAction = 3
	P2pActionGetTokenProof  P2pAction = 4
	P2pActionGetState       P2pAction = 5
	P2pActionSyncBlock      P2pAction = 6
)

type P2pChannelFlow added in v1.2.0

type P2pChannelFlow int8

var config configs.MainConfiguration

const (
	P2pChannelOut P2pChannelFlow = 1
	P2pChannelIn  P2pChannelFlow = 2
)

type P2pEventResponse added in v1.2.0

type P2pEventResponse struct {
	Event  json.RawMessage   `json:"e"`
	States []json.RawMessage `json:"s"`
}

func GetEvent added in v1.2.0

func GetState added in v1.2.0

func GetState(config *configs.MainConfiguration, path entities.EntityPath, validator *entities.PublicKeyString, result any) (*P2pEventResponse, error)

func UnpackP2pEventResponse added in v1.2.0

func UnpackP2pEventResponse(b []byte) (P2pEventResponse, error)

func (*P2pEventResponse) MsgPack added in v1.2.0

func (hs *P2pEventResponse) MsgPack() []byte

func (P2pEventResponse) Unpack added in v1.2.0

func (hs P2pEventResponse) Unpack(b []byte) error

type P2pPayload added in v1.2.0

type P2pPayload struct {
	// Messages is a channel of messages received from other peers in the chat channel
	Id           string             `json:"id"`
	Data         json.RawMessage    `json:"d"`
	ChainId      configs.ChainId    `json:"pre"`
	Timestamp    uint64             `json:"ts"`
	Action       P2pAction          `json:"ac"`
	ResponseCode apperror.ErrorCode `json:"resp"`
	Error        string             `json:"err"`
	Signature    json.RawMessage    `json:"sig"`
	Signer       json.RawMessage    `json:"sign"`
	// contains filtered or unexported fields
}

func NewP2pPayload added in v1.2.0

func NewP2pPayload(config *configs.MainConfiguration, action P2pAction, data []byte) *P2pPayload

func UnpackP2pPayload added in v1.2.0

func UnpackP2pPayload(b []byte) (*P2pPayload, error)

func (P2pPayload) EncodeBytes added in v1.2.0

func (hsd P2pPayload) EncodeBytes() ([]byte, error)

func (*P2pPayload) IsValid added in v1.2.0

func (nma *P2pPayload) IsValid(chainId configs.ChainId) bool

func (*P2pPayload) MsgPack added in v1.2.0

func (hs *P2pPayload) MsgPack() []byte

func (*P2pPayload) SendDataRequest added in v1.2.0

func (p *P2pPayload) SendDataRequest(receiverPublicKey string) (*P2pPayload, error)

func (*P2pPayload) SendRequestToAddress added in v1.2.0

func (p *P2pPayload) SendRequestToAddress(privateKey []byte, address multiaddr.Multiaddr, _type RequestType) (*P2pPayload, error)

func (*P2pPayload) SendSyncRequest added in v1.2.0

func (p *P2pPayload) SendSyncRequest(receiverPublicKey string) (*P2pPayload, error)

func (*P2pPayload) Sign added in v1.2.0

func (p *P2pPayload) Sign(privateKey []byte) error

type Range added in v1.2.0

type Range struct {
	From json.RawMessage `json:"f"`
	To   json.RawMessage `json:"t"`
}

type RequestType added in v1.2.0

type RequestType int8
const (
	DataRequest RequestType = 1
	SyncRequest RequestType = 2
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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