diff --git a/ricochet.go b/ricochet.go index ca78446..65f0675 100644 --- a/ricochet.go +++ b/ricochet.go @@ -43,6 +43,8 @@ func (r *Ricochet) Connect(host string) (*OpenConnection, error) { return r.ConnectOpen(conn, host) } +// ConnectOpen attempts to open up a new connection to the given host. Returns a +// pointer to the OpenConnection or an error. func (r *Ricochet) ConnectOpen(conn net.Conn, host string) (*OpenConnection, error) { oc, err := r.negotiateVersion(conn, true) if err != nil { @@ -64,6 +66,8 @@ func (r *Ricochet) Server(service RicochetService, port int) { r.ServeListener(service, ln) } +// ServeListener processes all messages given by the listener ln with the given +// RicochetService, service. func (r *Ricochet) ServeListener(service RicochetService, ln net.Listener) { go r.ProcessMessages(service) service.OnReady() @@ -100,7 +104,7 @@ func (r *Ricochet) ProcessMessages(service RicochetService) { } } -// Request that the ProcessMessages loop is stopped after handling all currently +// RequestStopMessageLoop requests that the ProcessMessages loop is stopped after handling all currently // queued new connections. func (r *Ricochet) RequestStopMessageLoop() { r.newconns <- nil diff --git a/standardricochetservice.go b/standardricochetservice.go index 7398620..3c51d3c 100644 --- a/standardricochetservice.go +++ b/standardricochetservice.go @@ -138,7 +138,7 @@ func (srs *StandardRicochetService) OnOpenChannelRequest(oc *OpenConnection, cha func (srs *StandardRicochetService) OnOpenChannelRequestSuccess(oc *OpenConnection, channelID int32) { } -// OnChannelClose is called when a client or server closes an existing channel +// OnChannelClosed is called when a client or server closes an existing channel func (srs *StandardRicochetService) OnChannelClosed(oc *OpenConnection, channelID int32) { } diff --git a/utils/error.go b/utils/error.go index 830dfbe..7b21265 100644 --- a/utils/error.go +++ b/utils/error.go @@ -3,6 +3,7 @@ package utils import "fmt" import "log" +// RecoverFromError doesn't really recover from anything....see comment below func RecoverFromError() { if r := recover(); r != nil { // This should only really happen if there is a failure de/serializing. If @@ -12,6 +13,9 @@ func RecoverFromError() { } } +// CheckError is a helper function for panicing on errors which we need to handle +// but should be very rare e.g. failures deserializing a protobuf object that +// should only happen if there was a bug in the underlying library. func CheckError(err error) { if err != nil { panic(fmt.Sprintf("%v", err)) diff --git a/utils/networking.go b/utils/networking.go index 3b433e6..20343c9 100644 --- a/utils/networking.go +++ b/utils/networking.go @@ -14,6 +14,8 @@ type RicochetData struct { Data []byte } +//Equals compares a RicochetData object to another and returns true if contain +// the same data. func (rd RicochetData) Equals(other RicochetData) bool { return rd.Channel == other.Channel && bytes.Equal(rd.Data, other.Data) }