ospc

package
v0.0.0-...-f76cd81 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataEncodingBinary = iota
	DataEncodingString
	DataEncodingArrayBuffer
)
View Source
const (
	MdnsServiceType = "_openscreen._udp"
	MdnsDomain      = "local"
)
View Source
const (
	ALPN_OSP = "OSP"
)

Variables

View Source
var ErrConnectionClosed = errors.New("connection closed")
View Source
var ErrDiscovererClosed = errors.New("discoverer closed")
View Source
var ErrHandedOff = errors.New("connection handed off")
View Source
var ErrListenerClosed = errors.New("listener closed")

Functions

This section is empty.

Types

type ALPNListener

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

ALPNListener allows listening for application protocols on the same port as OSP.

func (*ALPNListener) Accept

func (l *ALPNListener) Accept(ctx context.Context) (quic.Connection, error)

func (*ALPNListener) Close

func (l *ALPNListener) Close() error

type ALPNListenerConfig

type ALPNListenerConfig struct {
	VerifyConnection func(cs tls.ConnectionState) error
}

type Agent

type Agent struct {
	PeerID PeerID

	Certificate          *tls.Certificate
	CertificateSNBase    uint32
	CertificateSNCounter uint32
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(c AgentConfig) (*Agent, error)

func (*Agent) AuthenticationInfo

func (a *Agent) AuthenticationInfo() *AgentAuthenticationInfo

func (*Agent) CertificateFingerPrint

func (a *Agent) CertificateFingerPrint() (string, error)

func (*Agent) HasAuthenticationInfo

func (a *Agent) HasAuthenticationInfo() bool

func (*Agent) HasInfo

func (a *Agent) HasInfo() bool

func (*Agent) Info

func (a *Agent) Info() *AgentInfo

func (*Agent) NewRemoteAgent

func (a *Agent) NewRemoteAgent(conn quic.Connection) (*Agent, error)

type AgentAuthenticationInfo

type AgentAuthenticationInfo struct {
	PSKConfig PSKConfig
}

type AgentConfig

type AgentConfig struct {
	// ID
	PeerID            PeerID
	Certificate       *tls.Certificate
	CertificateSNBase uint32

	// Info
	DisplayName string
	ModelName   string
	Locales     []string

	// AuthInfo
	PSKConfig PSKConfig
}

func NewAgentConfig

func NewAgentConfig(nickname string) AgentConfig

func (*AgentConfig) WithCertificateSNBase

func (c *AgentConfig) WithCertificateSNBase(snBase uint32)

func (*AgentConfig) WithModelName

func (c *AgentConfig) WithModelName(easeOfInput, entropy int)

func (*AgentConfig) WithPSKConfig

func (c *AgentConfig) WithPSKConfig(easeOfInput, entropy int)

type AgentInfo

type AgentInfo struct {
	DisplayName string
	ModelName   string
	// Capabilities []agentCapability
	// StateToken string // TODO: State token
	Locales []string
}

type AgentRole

type AgentRole int
const (
	AgentRoleClient AgentRole = 0
	AgentRoleServer AgentRole = 1
)

type AgentState

type AgentState struct {
	StateToken string // 8 characters in the range [0-9A-Za-z]
	RequestId  uint64
}

type AuthenticationRole

type AuthenticationRole int
const (
	AuthenticationRolePresenter AuthenticationRole = 0
	AuthenticationRoleConsumer  AuthenticationRole = 1
)

func (AuthenticationRole) String

func (t AuthenticationRole) String() string

type Connection

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

Connection

func (*Connection) AcceptDataChannel

func (c *Connection) AcceptDataChannel(ctx context.Context) (*DataChannel, error)

AcceptStream accepts a data channel

func (*Connection) AcceptTransport

func (c *Connection) AcceptTransport(ctx context.Context) (*Transport, error)

func (*Connection) Close

func (c *Connection) Close() error

Close the connection and all associated steams.

func (*Connection) LocalAgent

func (c *Connection) LocalAgent() *Agent

func (*Connection) NewTransport

func (c *Connection) NewTransport(ctx context.Context) (*Transport, error)

NewTransport

func (*Connection) NewTransportListener

func (c *Connection) NewTransportListener() (*Transport, error)

func (*Connection) OpenDataChannel

func (c *Connection) OpenDataChannel(ctx context.Context, params DataChannelParameters) (*DataChannel, error)

OpenDataChannel opens a data channel

func (*Connection) RemoteAgent

func (c *Connection) RemoteAgent() *Agent

type DataChannel

type DataChannel struct {
	DataChannelParameters
	// contains filtered or unexported fields
}

func (*DataChannel) Close

func (c *DataChannel) Close() error

Close closes the DataChannel and the underlying Quic stream.

func (*DataChannel) Read

func (c *DataChannel) Read(p []byte) (int, error)

Read reads a packet of len(p) bytes as binary data

func (*DataChannel) ReadDataChannel

func (c *DataChannel) ReadDataChannel(p []byte) (int, DataEncoding, error)

ReadDataChannel reads a packet of len(p) bytes

func (*DataChannel) ReceiveMessage

func (c *DataChannel) ReceiveMessage() ([]byte, error)

ReceiveMessage

func (*DataChannel) ReceiveMessageWithEncoding

func (c *DataChannel) ReceiveMessageWithEncoding() ([]byte, DataEncoding, error)

ReceiveMessageWithEncoding

func (*DataChannel) SendMessage

func (c *DataChannel) SendMessage(payload []byte) error

SendMessage

func (*DataChannel) SendMessageWithEncoding

func (c *DataChannel) SendMessageWithEncoding(payload []byte, enc DataEncoding) error

SendMessageWithEncoding

func (*DataChannel) Write

func (c *DataChannel) Write(p []byte) (n int, err error)

Write writes len(p) bytes from p as binary data

func (*DataChannel) WriteDataChannel

func (c *DataChannel) WriteDataChannel(p []byte, enc DataEncoding) (n int, err error)

WriteDataChannel writes len(p) bytes from p

type DataChannelParameters

type DataChannelParameters struct {
	Label    string
	Protocol string
	ID       uint64
}

DataChannelParameters

type DataEncoding

type DataEncoding uint64

DataEncoding represents pre-agreed EncodingIds used in exchange-data.

type DiscoveredAgent

type DiscoveredAgent struct {
	PeerID PeerID
	TXT    TXTRecordSet
	// contains filtered or unexported fields
}

DiscoveredAgent represents a discovered remote agent that has not been contacted yet.

func (DiscoveredAgent) Dial

Dial opens a connection to the remote agent.

func (*DiscoveredAgent) Nickname

func (a *DiscoveredAgent) Nickname() string

Nickname of the remote agent

type Discoverer

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

Discoverer is used to discover agents.

func Discover

func Discover() (*Discoverer, error)

Discover agents

func NewDiscoverer

func NewDiscoverer() *Discoverer

NewDiscoverer creates a new Discoverer

func (*Discoverer) Accept

func (d *Discoverer) Accept(ctx context.Context) (*DiscoveredAgent, error)

Accept returns an a discovered agent. It should be called in a loop.

func (*Discoverer) Close

func (d *Discoverer) Close() error

Close closes the discoverer. Any blocked Accept operations will be unblocked and return errors.

func (*Discoverer) Start

func (d *Discoverer) Start() error

Start discovering agents

func (*Discoverer) WithNickname

func (d *Discoverer) WithNickname(nickname string)

WithNickname defines a nickname of agents to discover.

type Listener

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

Listener acts as an advertising OSP agent and listens for incoming connections.

func Listen

func Listen(a *Agent) (*Listener, error)

Listen starts an advertising agent and listens for incoming connections.

func NewListener

func NewListener(a *Agent) *Listener

NewListener creates a new Listener

func (*Listener) Accept

Accept returns an a discovered agent. It should be called in a loop.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*Listener) ListenApplication

func (l *Listener) ListenApplication(alpn string, config *ALPNListenerConfig) *ALPNListener

ListenApplication allows you to listen for quic connections on the same port but with a different ALPN. Only one per ALPN is allowed. Needs to be registered before starting the Listener.

func (*Listener) Start

func (l *Listener) Start() error

type PSKConfig

type PSKConfig struct {
	EaseOfInput int // 0-100
	Entropy     int // 20-60 bits
}

type PeerID

type PeerID string

PeerID is a unique identifier for a peer, it is equal tot the OSP agent fingerprint (FP) of the peer.

type QuicStream

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

Stream

func (*QuicStream) Close

func (s *QuicStream) Close() error

func (*QuicStream) Read

func (s *QuicStream) Read(p []byte) (int, error)

func (*QuicStream) StreamID

func (s *QuicStream) StreamID() int64

func (*QuicStream) Write

func (s *QuicStream) Write(p []byte) (n int, err error)

type TXTRecordSet

type TXTRecordSet map[string][]string

func (TXTRecordSet) Add

func (r TXTRecordSet) Add(key, value string)

func (TXTRecordSet) FromSlice

func (r TXTRecordSet) FromSlice(in []string) error

func (TXTRecordSet) Get

func (r TXTRecordSet) Get(key string) []string

func (TXTRecordSet) GetOne

func (r TXTRecordSet) GetOne(key string) (string, error)

func (TXTRecordSet) Set

func (r TXTRecordSet) Set(key, value string)

func (TXTRecordSet) ToSlice

func (r TXTRecordSet) ToSlice() []string

type Transport

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

Transport implements WebTransport pooled over an existing OpenScreenProtocol connection.

func (*Transport) AcceptStream

func (t *Transport) AcceptStream(ctx context.Context) (*QuicStream, error)

func (*Transport) CloseWithError

func (t *Transport) CloseWithError(uint64, string) error

func (*Transport) OpenStreamSync

func (t *Transport) OpenStreamSync(ctx context.Context) (*QuicStream, error)

type TransportListener

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

func (*TransportListener) Accept

func (l *TransportListener) Accept(ctx context.Context) (*Transport, error)

func (*TransportListener) Close

func (l *TransportListener) Close() error

type TypeKey

type TypeKey uint64

type UnauthenticatedConnection

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

UnauthenticatedConnection represents an OSPC connection that didn't pass authentication yet.

func (*UnauthenticatedConnection) AcceptAuthenticate

func (c *UnauthenticatedConnection) AcceptAuthenticate(ctx context.Context) (role AuthenticationRole, err error)

AcceptAuthenticate is used to handle an incoming authentication request. It has to be called for every UnauthenticatedConnection.

func (*UnauthenticatedConnection) AuthenticatePSK

func (c *UnauthenticatedConnection) AuthenticatePSK(ctx context.Context, psk []byte) (*Connection, error)

Authenticate is used to authenticate. It will block until authentication is complete or the context is closed.

func (*UnauthenticatedConnection) Close

func (c *UnauthenticatedConnection) Close() error

Close the unauthenticated connection. If the connection has progressed to authenticated, it is not closed but an error is returned. This allows for defer closing regardless.

func (*UnauthenticatedConnection) GeneratePSK

func (c *UnauthenticatedConnection) GeneratePSK() ([]byte, error)

GeneratePSK creates a PSK based on the negotiated config.

func (*UnauthenticatedConnection) GetAuthenticationRole

func (c *UnauthenticatedConnection) GetAuthenticationRole() AuthenticationRole

GetAuthenticationRole determines if the agent should act as presenter or consumer of the PSK.

func (*UnauthenticatedConnection) LocalAgent

func (c *UnauthenticatedConnection) LocalAgent() *Agent

LocalAgent provides info about local agent

func (*UnauthenticatedConnection) RemoteAgent

func (c *UnauthenticatedConnection) RemoteAgent() *Agent

RemoteAgent provides info about remote agent

func (*UnauthenticatedConnection) RequestAuthenticatePSK

func (c *UnauthenticatedConnection) RequestAuthenticatePSK() error

RequestAuthenticatePSK is used to request authentication as an initiating collector agent.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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