Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKey() (PublicKey, PrivateKey, error)
- func RegisterContactUnserializer()
- type Channel
- type ChannelHandler
- type ChannelSender
- type ContactDefinition
- type Context
- type Dialer
- type HandlerFunc
- type Listener
- type Message
- type PrivateKey
- type PublicKey
- type STUNDetectionStatus
Constants ¶
const ( // TopicKeepAlive is keep alive endpoint. TopicKeepAlive = "p2p-keepalive" // TopicSessionCreate is a session create endpoint for p2p communication. TopicSessionCreate = "p2p-session-create" // TopicSessionAcknowledge is a session acknowledge endpoint for p2p communication. TopicSessionAcknowledge = "p2p-session-acknowledge" // TopicSessionStatus is a session status notification for p2p communication. TopicSessionStatus = "p2p-session-connectivity-status" // TopicSessionDestroy is a session destroy endpoint for p2p communication. TopicSessionDestroy = "p2p-session-destroy" // TopicPaymentMessage is a payment messages endpoint for p2p communication. TopicPaymentMessage = "p2p-payment-message" // TopicPaymentInvoice is a payment invoices endpoint for p2p communication. TopicPaymentInvoice = "p2p-payment-invoice" )
const AppTopicSTUN = "STUN detection"
AppTopicSTUN represents the STUN detection topic.
const (
// ContactTypeV1 is p2p contact type.
ContactTypeV1 = "nats/p2p/v1"
)
Variables ¶
var ( // ErrSendTimeout indicates send timeout error. ErrSendTimeout = errors.New("p2p send timeout") // ErrHandlerNotFound indicates that peer is not registered handler yet. ErrHandlerNotFound = errors.New("p2p peer handler not found") )
var ErrContactNotFound = errors.New("p2p contact not found")
ErrContactNotFound represents that no p2p contact is found.
Functions ¶
func GenerateKey ¶
func GenerateKey() (PublicKey, PrivateKey, error)
GenerateKey generates p2p public and private key pairs.
func RegisterContactUnserializer ¶
func RegisterContactUnserializer()
RegisterContactUnserializer registers global proposal contact unserializer.
Types ¶
type Channel ¶
type Channel interface { ChannelSender ChannelHandler // Tracer returns tracer which tracks channel establishment Tracer() *trace.Tracer // ServiceConn returns UDP connection which can be used for services. ServiceConn() *net.UDPConn // Conn returns underlying channel's UDP connection. Conn() *net.UDPConn // Close closes p2p communication channel. Close() error // Unique ID ID() string }
Channel represents p2p communication channel which can send and receive messages over encrypted and reliable UDP transport.
type ChannelHandler ¶
type ChannelHandler interface { // Handle registers handler for given topic which handles peer request. Handle(topic string, handler HandlerFunc) }
ChannelHandler is used to handle messages.
type ChannelSender ¶
type ChannelSender interface { // Send sends message to given topic. Peer listening to topic will receive message. Send(ctx context.Context, topic string, msg *Message) (*Message, error) }
ChannelSender is used to send messages.
type ContactDefinition ¶
type ContactDefinition struct {
BrokerAddresses []string `json:"broker_addresses"`
}
ContactDefinition represents p2p contact which contains NATS broker addresses for connection.
func ParseContact ¶
func ParseContact(contacts market.ContactList) (ContactDefinition, error)
ParseContact tries to parse p2p contact from given contacts list.
type Context ¶
type Context interface { // Request returns message with data bytes. Request() *Message // Error allows to return error which will be seen for peer. Error(err error) error // OkWithReply indicates that request was handled successfully and returns reply with given message. OkWithReply(msg *Message) error // Ok indicates that request was handled successfully OK() error // PeerID returns peer identity used to authenticate P2P channel PeerID() identity.Identity }
Context represents request context.
type Dialer ¶
type Dialer interface { // Dial exchanges p2p configuration via broker, performs NAT pinging if needed // and create p2p channel which is ready for communication. Dial(ctx context.Context, consumerID, providerID identity.Identity, serviceType string, contactDef ContactDefinition, tracer *trace.Tracer) (Channel, error) }
Dialer knows how to exchange p2p keys and encrypted configuration and creates ready to use p2p channels.
func NewDialer ¶
func NewDialer(broker brokerConnector, signer identity.SignerFactory, verifierFactory identity.VerifierFactory, ipResolver ip.Resolver, portPool port.ServicePortSupplier, eventBus eventbus.EventBus) Dialer
NewDialer creates new p2p communication dialer which is used on consumer side.
type HandlerFunc ¶
HandlerFunc is channel request handler func signature.
type Listener ¶
type Listener interface { // Listen listens for incoming peer connections to establish new p2p channels. Establishes p2p channel and passes it // to channelHandlers Listen(providerID identity.Identity, serviceType string, channelHandler func(ch Channel)) (func(), error) // GetContact returns contract which is later can be added to proposal contacts definition so consumer can // know how to connect to this p2p listener. GetContact() market.Contact }
Listener knows how to exchange p2p keys and encrypted configuration and creates ready to use p2p channels.
func NewListener ¶
func NewListener(brokerConn nats.Connection, signer identity.SignerFactory, verifier identity.Verifier, ipResolver ip.Resolver, eventBus eventbus.EventBus) Listener
NewListener creates new p2p communication listener which is used on provider side.
type Message ¶
type Message struct {
Data []byte
}
Message represent message with data bytes.
func ProtoMessage ¶
ProtoMessage is convenient helper to return message with marshaled proto data bytes.
type PrivateKey ¶
type PrivateKey [32]byte
PrivateKey represents p2p private key.
type PublicKey ¶
type PublicKey [keySize]byte
PublicKey represents p2p public key part.
func DecodePublicKey ¶
DecodePublicKey converts hex string to PublicKey.
type STUNDetectionStatus ¶
STUNDetectionStatus represents information about detected NAT type using STUN servers.