Add methods to run protocol over external sockets & listeners

The ServeListener and ConnectOpen methods take an active Listener or
Conn respectively, instead of creating their own.
This commit is contained in:
John Brooks 2016-10-01 15:50:11 -07:00 committed by Sarah Jamie Lewis
parent bfe5b74364
commit f6d6991f46
1 changed files with 8 additions and 0 deletions

View File

@ -39,6 +39,10 @@ func (r *Ricochet) Connect(host string) (*OpenConnection, error) {
return nil, err
}
return r.ConnectOpen(conn, host)
}
func (r *Ricochet) ConnectOpen(conn net.Conn, host string) (*OpenConnection, error) {
oc, err := r.negotiateVersion(conn, true)
if err != nil {
return nil, err
@ -56,6 +60,10 @@ func (r *Ricochet) Server(service RicochetService, port int) {
return
}
r.ServeListener(service, ln)
}
func (r *Ricochet) ServeListener(service RicochetService, ln net.Listener) {
go r.ProcessMessages(service)
service.OnReady()
for {