Documentation ¶
Index ¶
- Constants
- Variables
- type Addr
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) ReadPacket() ([]byte, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (*Conn) SetDeadline(time.Time) error
- func (*Conn) SetReadDeadline(time.Time) error
- func (*Conn) SetWriteDeadline(time.Time) error
- func (c *Conn) Write(b []byte) (n int, err error)
- type Credentials
- type Dialer
- type ICEServer
- type ListenConfig
- type Listener
- type Notifier
- type Signal
- type Signaling
Constants ¶
const ( // SignalTypeOffer is sent by client to request a connection to the remote host. Signals that have // SignalTypeOffer usually has a data of local description of its connection. SignalTypeOffer = "CONNECTREQUEST" // SignalTypeAnswer is sent by server to respond to Signals that have SignalTypeOffer. Signals that // have SignalTypeAnswer usually has a data of local description of the host. SignalTypeAnswer = "CONNECTRESPONSE" // SignalTypeCandidate is sent by both server and client to notify a local candidate to // remote connection. This is usually sent after SignalTypeOffer or SignalTypeAnswer by server/client. // Signals that have SignalTypeCandidate usually has a data of local candidate gathered with additional // credentials received from the Signaling implementation. SignalTypeCandidate = "CANDIDATEADD" // SignalTypeError is sent by both server and client to notify an error has occurred. // Signals that have SignalTypeError has a Data of the code of error occurred, which is listed // on the following constants. SignalTypeError = "CONNECTERROR" )
const ( ErrorCodeNone = iota ErrorCodeDestinationNotLoggedIn ErrorCodeNegotiationTimeout ErrorCodeWrongTransportVersion ErrorCodeFailedToCreatePeerConnection ErrorCodeICE ErrorCodeConnectRequest ErrorCodeConnectResponse ErrorCodeCandidateAdd ErrorCodeInactivityTimeout ErrorCodeFailedToCreateOffer ErrorCodeFailedToCreateAnswer ErrorCodeFailedToSetLocalDescription ErrorCodeFailedToSetRemoteDescription ErrorCodeNegotiationTimeoutWaitingForResponse ErrorCodeNegotiationTimeoutWaitingForAccept ErrorCodeIncomingConnectionIgnored ErrorCodeSignalingParsingFailure ErrorCodeSignalingUnknownError ErrorCodeSignalingUnicastMessageDeliveryFailed ErrorCodeSignalingBroadcastDeliveryFailed ErrorCodeSignalingMessageDeliveryFailed ErrorCodeSignalingTurnAuthFailed ErrorCodeSignalingFallbackToBestEffortDelivery ErrorCodeNoSignalingChannel ErrorCodeNotLoggedIn ErrorCodeSignalingFailedToSend )
Variables ¶
var ErrSignalingCanceled = errors.New("nethernet: canceled")
Functions ¶
This section is empty.
Types ¶
type Addr ¶
Addr represents a net.Addr from the ConnectionID and NetworkID. It also includes a slice of remote Candidates signaled from the remote connection.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) LocalAddr ¶
LocalAddr returns an Addr of local network ID. It also contains locally-gathered ICE candidates.
func (*Conn) ReadPacket ¶
func (*Conn) RemoteAddr ¶
RemoteAddr returns an Addr of remote network ID. It also contains remotely-signaled ICE candidates.
type Credentials ¶
type Dialer ¶
type Dialer struct {
// NetworkID and ConnectionID are the local IDs of a Conn being established. If
// left as zero, a random value will automatically set from rand.Uint64.
NetworkID, ConnectionID uint64
// API specifies custom configuration for WebRTC transports, and data channels.
API *webrtc.API
// Log is used to output several messages at many log levels. If left as nil, the
// default [slog.Logger] will be set from [slog.Default].
Log *slog.Logger
}
func (Dialer) DialContext ¶
func (d Dialer) DialContext(ctx context.Context, networkID uint64, signaling Signaling) (*Conn, error)
DialContext establishes a connection with the remote network ID. An implementation of Signaling is used to signal an offer and local candidates, and receiving answer and remote candidates. The context.Context may be used to cancel the connection as soon as possible. A Conn may be returned, that is ready to receive and send packets.
type ListenConfig ¶
type ListenConfig struct { // Log is used to output several messages at many log levels. If left as nil, the // default [slog.Logger] will be set from [slog.Default]. Log *slog.Logger // API specifies custom configuration for WebRTC transports, and data channels. API *webrtc.API ConnContext func(conn *Conn) context.Context }
func (ListenConfig) Listen ¶
func (conf ListenConfig) Listen(networkID uint64, signaling Signaling) (*Listener, error)
Listen listens on the local network ID. The Signaling implementation is used to receive signals from the remote connections. A Listener will be returned, that is ready to accept established Conn.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener implements a NetherNet connection listener.
func (*Listener) Accept ¶
Accept waits for and returns the next Conn to the listener. An error may be returned, if the listener has been closed.
type Signal ¶
type Signal struct { // Type is the type of Signal. It is one of the constants defined above. Type string // ConnectionID is the unique ID of the connection that has sent the Signal. // It is encoded in String as a second segment to identify a connection uniquely. ConnectionID uint64 // Data is the actual data of the Signal. Data string // NetworkID is used internally by the implementations of Signaling type // to reference a remote network with a number. NetworkID uint64 }
func (*Signal) MarshalText ¶
func (*Signal) UnmarshalText ¶
type Signaling ¶
type Signaling interface { Signal(signal *Signal) error Notify(cancel <-chan struct{}, n Notifier) // Credentials will currently block until a credentials has received from the signaling service. This is usually // present in WebSocket signaling connection. A nil *Credentials may be returned if no credentials or // the implementation is not capable to do that. Credentials() (*Credentials, error) }