Documentation
¶
Index ¶
- Constants
- Variables
- func P2PVersionString(version P2PVersionType) string
- type CertificateGeneratorType
- type CertificatesType
- type Description
- type NetError
- type P2PConn
- func (conn *P2PConn) Close() error
- func (conn *P2PConn) Connect(ctx context.Context, remoteDescriptionString string) error
- func (conn *P2PConn) DiscoverIP() (bool, error)
- func (conn *P2PConn) Listen(port int) (string, error)
- func (conn *P2PConn) LocalAddr() net.Addr
- func (conn *P2PConn) LocalDescription() (string, error)
- func (conn *P2PConn) Read(b []byte) (int, error)
- func (conn *P2PConn) RemoteAddr() net.Addr
- func (conn *P2PConn) SetDeadline(t time.Time) error
- func (conn *P2PConn) SetReadDeadline(t time.Time) error
- func (conn *P2PConn) SetWriteDeadline(t time.Time) error
- func (conn *P2PConn) Write(b []byte) (int, error)
- type P2PVersionType
Constants ¶
const CertificateServerName = "easyp2p.go"
CertificateServerName is the default server name for the quic server
const InitialRetryingInterval = 25 * time.Millisecond
InitialRetryingInterval is the interval after the first attempt to connect
const RetryingIntervalMultiplied = time.Duration(2)
RetryingIntervalMultiplied : the interval is multiplied by this number as many times as we try to connect
Variables ¶
var ErrDifferentProtocol = newError("Different protocol", false, false)
ErrDifferentProtocol is returned when protocols don't match.
var ErrDisconnected = newError("Disconnected", false, false)
ErrDisconnected is returned when the connection is closed or not established.
var ErrInsufficientLocalAdrdesses = newError("Insufficient local addresses", false, false)
ErrInsufficientLocalAdrdesses is returned when DiscoverIP() can find no addresses
var ErrInvalidCACertificate = newError("Invalid CA Certificate", false, false)
ErrInvalidCACertificate is returned when the given CA certificate is invalid
Functions ¶
func P2PVersionString ¶
func P2PVersionString(version P2PVersionType) string
P2PVersionString converts P2PVersionType into string
Types ¶
type CertificateGeneratorType ¶
type CertificateGeneratorType func() (CertificatesType, error)
CertificateGeneratorType is the type of functions which create certificates. DNS names in the certificate of the server must be CertificateServerName(easyp2p.go)
type CertificatesType ¶
type CertificatesType struct { CACertPEM []byte Cert tls.Certificate }
CertificatesType needs to contain a certificate of CA as PEM and a certificate created with the CA
func NewSelfSignedCertificate ¶
func NewSelfSignedCertificate() (out CertificatesType, retErr error)
NewSelfSignedCertificate is the default function of CertificateGeneratorType
type Description ¶
type Description struct { ProtocolVersion P2PVersionType LocalAddresses []string Identifier string CAPEM []byte }
Description is the type of local and remote description given between two peers
type NetError ¶
type NetError struct {
// contains filtered or unexported fields
}
NetError is the error type of net.Error
type P2PConn ¶
type P2PConn struct { RawConn *net.UDPConn ReliableConn net.Conn CertificateFunc CertificateGeneratorType IPDiscoveryTimeout time.Duration IPDiscoveryServers []string LocalAddresses []string Identifier string // contains filtered or unexported fields }
P2PConn is the type of P2P connection
func NewP2PConn ¶
NewP2PConn returns a new P2PConn
func (*P2PConn) Close ¶
Close closes the connection. (sync) This will block until closing connections completes.
func (*P2PConn) Connect ¶
Connect tries to connect to the peer. remoteDescription needs to be given from the other peer
func (*P2PConn) DiscoverIP ¶
DiscoverIP finds local addresses from STUN servers and network interfaces The first boolean value is whether one address at least is found or not.
func (*P2PConn) Listen ¶
Listen opens a port and returns the local address. If 0, ports will be automatically selected
func (*P2PConn) LocalDescription ¶
LocalDescription returns a local description which needs to be passed to the other peer
func (*P2PConn) Read ¶
Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*P2PConn) RemoteAddr ¶
RemoteAddr returns the remote network address
func (*P2PConn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.
func (*P2PConn) SetReadDeadline ¶
SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.
func (*P2PConn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.
type P2PVersionType ¶
type P2PVersionType uint32
P2PVersionType is the type of the protocol of P2P
const ( // P2PVersion1_0 : 1.0 P2PVersion1_0 P2PVersionType = 1000 // P2PVersion1_1 : 1.1 P2PVersion1_1 P2PVersionType = 1100 // P2PVersion2_0 : 2.0 P2PVersion2_0 P2PVersionType = 2000 // P2PVersionLatest is the alias to the latest version P2PVersionLatest = P2PVersion2_0 )
func (P2PVersionType) String ¶
func (p P2PVersionType) String() string