forked from openprivacy/libricochet-go
Application comments and notes
This commit is contained in:
parent
4b700d4223
commit
6e2bfbbc14
|
@ -27,6 +27,7 @@ func (ra *RicochetApplication) Init(pk *rsa.PrivateKey, af ApplicationInstanceFa
|
||||||
ra.contactManager = cm
|
ra.contactManager = cm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Reimplement OnJoin, OnLeave Events.
|
||||||
func (ra *RicochetApplication) handleConnection(conn net.Conn) {
|
func (ra *RicochetApplication) handleConnection(conn net.Conn) {
|
||||||
rc, err := goricochet.NegotiateVersionInbound(conn)
|
rc, err := goricochet.NegotiateVersionInbound(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,9 +61,7 @@ func (ra *RicochetApplication) Broadcast(do func(rai *ApplicationInstance)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ra *RicochetApplication) Shutdown() {
|
func (ra *RicochetApplication) Shutdown() {
|
||||||
log.Printf("Closing")
|
|
||||||
ra.l.Close()
|
ra.l.Close()
|
||||||
log.Printf("Closed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ra *RicochetApplication) Run(l net.Listener) {
|
func (ra *RicochetApplication) Run(l net.Listener) {
|
||||||
|
@ -76,7 +75,6 @@ func (ra *RicochetApplication) Run(l net.Listener) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
go ra.handleConnection(conn)
|
go ra.handleConnection(conn)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Closing")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,29 +5,29 @@ import (
|
||||||
"github.com/s-rah/go-ricochet/connection"
|
"github.com/s-rah/go-ricochet/connection"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A concrete instance of a ricochet application, encapsulating a connection
|
// ApplicationInstance is a concrete instance of a ricochet application, encapsulating a connection
|
||||||
type ApplicationInstance struct {
|
type ApplicationInstance struct {
|
||||||
connection.AutoConnectionHandler
|
connection.AutoConnectionHandler
|
||||||
Connection *connection.Connection
|
Connection *connection.Connection
|
||||||
RemoteHostname string
|
RemoteHostname string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Application instance factory
|
// ApplicationInstanceFactory
|
||||||
type ApplicationInstanceFactory struct {
|
type ApplicationInstanceFactory struct {
|
||||||
handlerMap map[string]func(*ApplicationInstance) func() channels.Handler
|
handlerMap map[string]func(*ApplicationInstance) func() channels.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init setsup an Application Factory
|
// Init sets up an Application Factory
|
||||||
func (af *ApplicationInstanceFactory) Init() {
|
func (af *ApplicationInstanceFactory) Init() {
|
||||||
af.handlerMap = make(map[string]func(*ApplicationInstance) func() channels.Handler)
|
af.handlerMap = make(map[string]func(*ApplicationInstance) func() channels.Handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddHandler
|
// AddHandler defines a channel type -> handler construct function
|
||||||
func (af *ApplicationInstanceFactory) AddHandler(ctype string, chandler func(*ApplicationInstance) func() channels.Handler) {
|
func (af *ApplicationInstanceFactory) AddHandler(ctype string, chandler func(*ApplicationInstance) func() channels.Handler) {
|
||||||
af.handlerMap[ctype] = chandler
|
af.handlerMap[ctype] = chandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetApplicationInstance,
|
// GetApplicationInstance buulds a new application instance using a connection as a base.
|
||||||
func (af *ApplicationInstanceFactory) GetApplicationInstance(rc *connection.Connection) *ApplicationInstance {
|
func (af *ApplicationInstanceFactory) GetApplicationInstance(rc *connection.Connection) *ApplicationInstance {
|
||||||
rai := new(ApplicationInstance)
|
rai := new(ApplicationInstance)
|
||||||
rai.Init()
|
rai.Init()
|
||||||
|
@ -38,3 +38,4 @@ func (af *ApplicationInstanceFactory) GetApplicationInstance(rc *connection.Conn
|
||||||
}
|
}
|
||||||
return rai
|
return rai
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue