|
|
@ -18,6 +18,7 @@ type Service interface { |
|
|
|
Connect(hostname string, application Application) (bool, error) |
|
|
|
Listen(application Application) error |
|
|
|
GetConnection(connectionID string) (Connection, error) |
|
|
|
Broadcast(message []byte, capability Capability) error |
|
|
|
WaitForCapabilityOrClose(connectionID string, capability Capability) (Connection, error) |
|
|
|
Shutdown() |
|
|
|
} |
|
|
@ -37,6 +38,7 @@ type Connection interface { |
|
|
|
App() Application |
|
|
|
SetApp(application Application) |
|
|
|
IsClosed() bool |
|
|
|
Broadcast(message []byte, capability Capability) error |
|
|
|
} |
|
|
|
|
|
|
|
// Connection defines a Tapir Connection
|
|
|
@ -52,17 +54,19 @@ type connection struct { |
|
|
|
closed bool |
|
|
|
MaxLength int |
|
|
|
lock sync.Mutex |
|
|
|
service Service |
|
|
|
} |
|
|
|
|
|
|
|
// NewConnection creates a new Connection
|
|
|
|
func NewConnection(id *primitives.Identity, hostname string, outbound bool, conn io.ReadWriteCloser, app Application) Connection { |
|
|
|
func NewConnection(service Service, id *primitives.Identity, hostname string, outbound bool, conn io.ReadWriteCloser, app Application) Connection { |
|
|
|
connection := new(connection) |
|
|
|
connection.hostname = hostname |
|
|
|
connection.conn = conn |
|
|
|
connection.app = app |
|
|
|
connection.identity = id |
|
|
|
connection.outbound = outbound |
|
|
|
connection.MaxLength = 1024 |
|
|
|
connection.MaxLength = 8192 |
|
|
|
connection.service = service |
|
|
|
go connection.app.Init(connection) |
|
|
|
return connection |
|
|
|
} |
|
|
@ -204,3 +208,8 @@ func (c *connection) Send(message []byte) { |
|
|
|
c.closed = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Broadcast sends a message to all active service connections with a given capability
|
|
|
|
func (c *connection) Broadcast(message []byte, capability Capability) error { |
|
|
|
return c.service.Broadcast(message, capability) |
|
|
|
} |
|
|
|