diff --git a/applications/auth_test.go b/applications/auth_test.go index a00ced7..5c71c8f 100644 --- a/applications/auth_test.go +++ b/applications/auth_test.go @@ -2,6 +2,7 @@ package applications import ( "crypto/rand" + "cwtch.im/tapir" "cwtch.im/tapir/primitives" "encoding/json" "golang.org/x/crypto/ed25519" @@ -66,6 +67,11 @@ func (MockConnection) Close() { // no op } +func (MockConnection) App() tapir.Application { + // no op + return nil +} + func (MockConnection) IsClosed() bool { panic("implement me") } diff --git a/service.go b/service.go index 76815fd..0fbfcf9 100644 --- a/service.go +++ b/service.go @@ -35,6 +35,7 @@ type Connection interface { SetEncryptionKey(key [32]byte) Send(message []byte) Close() + App() Application IsClosed() bool } @@ -45,7 +46,7 @@ type connection struct { capabilities sync.Map encrypted bool key [32]byte - App Application + app Application identity *primitives.Identity outbound bool closed bool @@ -57,11 +58,11 @@ func NewConnection(id *primitives.Identity, hostname string, outbound bool, conn connection := new(connection) connection.hostname = hostname connection.conn = conn - connection.App = app + connection.app = app connection.identity = id connection.outbound = outbound connection.MaxLength = 1024 - go connection.App.Init(connection) + go connection.app.Init(connection) return connection } @@ -70,6 +71,11 @@ func (c *connection) ID() *primitives.Identity { return c.identity } +// App returns the overarching application using this Connection. +func (c *connection) App() Application { + return c.app +} + // Hostname returns the hostname of the connection (if the connection has not been authorized it will return the // temporary hostname identifier) func (c *connection) Hostname() string {