forked from cwtch.im/tapir
Exposing App() from Connection Interface
This commit is contained in:
parent
42d3cb196a
commit
164e91fa17
|
@ -2,6 +2,7 @@ package applications
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"cwtch.im/tapir"
|
||||||
"cwtch.im/tapir/primitives"
|
"cwtch.im/tapir/primitives"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
|
@ -66,6 +67,11 @@ func (MockConnection) Close() {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (MockConnection) App() tapir.Application {
|
||||||
|
// no op
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (MockConnection) IsClosed() bool {
|
func (MockConnection) IsClosed() bool {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
12
service.go
12
service.go
|
@ -35,6 +35,7 @@ type Connection interface {
|
||||||
SetEncryptionKey(key [32]byte)
|
SetEncryptionKey(key [32]byte)
|
||||||
Send(message []byte)
|
Send(message []byte)
|
||||||
Close()
|
Close()
|
||||||
|
App() Application
|
||||||
IsClosed() bool
|
IsClosed() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ type connection struct {
|
||||||
capabilities sync.Map
|
capabilities sync.Map
|
||||||
encrypted bool
|
encrypted bool
|
||||||
key [32]byte
|
key [32]byte
|
||||||
App Application
|
app Application
|
||||||
identity *primitives.Identity
|
identity *primitives.Identity
|
||||||
outbound bool
|
outbound bool
|
||||||
closed bool
|
closed bool
|
||||||
|
@ -57,11 +58,11 @@ func NewConnection(id *primitives.Identity, hostname string, outbound bool, conn
|
||||||
connection := new(connection)
|
connection := new(connection)
|
||||||
connection.hostname = hostname
|
connection.hostname = hostname
|
||||||
connection.conn = conn
|
connection.conn = conn
|
||||||
connection.App = app
|
connection.app = app
|
||||||
connection.identity = id
|
connection.identity = id
|
||||||
connection.outbound = outbound
|
connection.outbound = outbound
|
||||||
connection.MaxLength = 1024
|
connection.MaxLength = 1024
|
||||||
go connection.App.Init(connection)
|
go connection.app.Init(connection)
|
||||||
return connection
|
return connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +71,11 @@ func (c *connection) ID() *primitives.Identity {
|
||||||
return c.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
|
// Hostname returns the hostname of the connection (if the connection has not been authorized it will return the
|
||||||
// temporary hostname identifier)
|
// temporary hostname identifier)
|
||||||
func (c *connection) Hostname() string {
|
func (c *connection) Hostname() string {
|
||||||
|
|
Loading…
Reference in New Issue