From f6d6991f46fee5894f32333af0479a62ec86c539 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sat, 1 Oct 2016 15:50:11 -0700 Subject: [PATCH] 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. --- ricochet.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ricochet.go b/ricochet.go index a814b1c..66d9642 100644 --- a/ricochet.go +++ b/ricochet.go @@ -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 {