easyp2p

package module
v0.0.0-...-031ad43 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: MIT Imports: 24 Imported by: 3

README

go-easyp2p

GoDoc GoReportCard

Description

  • Easily usable P2P library
  • Pure Go
  • Secure with TLS

Examples

  • in examples/

Install

  • go get github.com/cs3238-tsuzu/go-easyp2p

License

  • Under the MIT License
  • Copyright (c) 2018 Tsuzu

TODO

  • Support TURN

Detail

Documentation

Index

Constants

View Source
const CertificateServerName = "easyp2p.go"

CertificateServerName is the default server name for the quic server

View Source
const InitialRetryingInterval = 25 * time.Millisecond

InitialRetryingInterval is the interval after the first attempt to connect

View Source
const RetryingIntervalMultiplied = time.Duration(2)

RetryingIntervalMultiplied : the interval is multiplied by this number as many times as we try to connect

Variables

View Source
var ErrDifferentProtocol = newError("Different protocol", false, false)

ErrDifferentProtocol is returned when protocols don't match.

View Source
var ErrDisconnected = newError("Disconnected", false, false)

ErrDisconnected is returned when the connection is closed or not established.

View Source
var ErrInsufficientLocalAdrdesses = newError("Insufficient local addresses", false, false)

ErrInsufficientLocalAdrdesses is returned when DiscoverIP() can find no addresses

View Source
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

func (*NetError) Temporary

func (ne *NetError) Temporary() bool

Temporary (refer to net.Error)

func (*NetError) Timeout

func (ne *NetError) Timeout() bool

Timeout (refer to 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

func NewP2PConn(ipDiscoveryServers []string) *P2PConn

NewP2PConn returns a new P2PConn

func (*P2PConn) Close

func (conn *P2PConn) Close() error

Close closes the connection. (sync) This will block until closing connections completes.

func (*P2PConn) Connect

func (conn *P2PConn) Connect(ctx context.Context, remoteDescriptionString string) error

Connect tries to connect to the peer. remoteDescription needs to be given from the other peer

func (*P2PConn) DiscoverIP

func (conn *P2PConn) DiscoverIP() (bool, error)

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

func (conn *P2PConn) Listen(port int) (string, error)

Listen opens a port and returns the local address. If 0, ports will be automatically selected

func (*P2PConn) LocalAddr

func (conn *P2PConn) LocalAddr() net.Addr

LocalAddr returns the local network address

func (*P2PConn) LocalDescription

func (conn *P2PConn) LocalDescription() (string, error)

LocalDescription returns a local description which needs to be passed to the other peer

func (*P2PConn) Read

func (conn *P2PConn) Read(b []byte) (int, error)

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

func (conn *P2PConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address

func (*P2PConn) SetDeadline

func (conn *P2PConn) SetDeadline(t time.Time) error

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

func (conn *P2PConn) SetReadDeadline(t time.Time) error

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

func (conn *P2PConn) SetWriteDeadline(t time.Time) error

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.

func (*P2PConn) Write

func (conn *P2PConn) Write(b []byte) (int, error)

Write writes data to the connection. Write can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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