Exposing App() from Connection Interface

This commit is contained in:
Sarah Jamie Lewis 2019-08-08 11:28:55 -07:00
parent 42d3cb196a
commit 164e91fa17
2 changed files with 15 additions and 3 deletions

View File

@ -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")
}

View File

@ -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 {