Commit Graph

21 Commits

Author SHA1 Message Date
Sarah Jamie Lewis e382c8eb69 Rename 2018-06-08 15:05:22 -07:00
Dan Ballard 5a94afa0f7 add application integration test: (#42)
- start two peers alice, bob
- make alice requests contact with bob
- they send messages
- they shutdown
- verify (and fix) no threads leaked
- verify messages
- add inbound connection handler to chatChannelHandler
- add Open and AcceptAllContactHandler to application
2018-05-30 10:51:40 -07:00
Sarah Jamie Lewis 1433b31e6f Change inbound/outbound handlers to use Identity.
Add Inbound Version Negotiation Test
2017-12-13 11:42:54 -08:00
Sarah Jamie Lewis 5057dd68ee Formatting + Checking Connection Error in Echobot 2017-11-02 16:45:27 -07:00
Sarah Jamie Lewis 8fe7b84fc9 Merge branch 'fix/chatchannel-api' of https://github.com/special/go-ricochet-protocol into special-fix/chatchannel-api 2017-11-02 15:45:09 -07:00
John Brooks 9a65aeed77 Improve ContactRequestChannel's API
After the RequestOpenChannel changes, it's now possible to specify the
name and message of an outbound request as variables of the channel handler,
instead implementing an interface method to return them.

Also added the SendResponse method, which is necessary to respond to an
inbound request that was in the Pending state.
2017-11-02 15:43:07 -07:00
John Brooks c24773809e Fix and document safety problems with Connection.Do
There were several issues with the Do function that made it nearly
impossible to write safe code.

First, Do cannot be called recursively -- it will deadlock. There is
actually no way to implement a safe and recursive Do (or mutex) in Go,
because there is no primitive that will identify the current goroutine.

RequestOpenChannel used Do internally, which made it impossible to open
channels safely in many circumstances. That has been removed, so all
calls to RequestOpenChannel must be changed to happen under Do now.

Do now has more documentation and a new rule: no code exposed through
API can use Do, unless it has sole custody of the connection (such as
ProcessAuthAsClient).

Related to that problem, Do was impossible to call from inside handlers
(or anything else on the process goroutine) -- it would again just
deadlock. This is resolved by wrapping calls into user code to continue
handling invocations of Do (and only those) while the handler is
executing.

There is a third issue with connection close, but it will be addressed
in a separate commit

And finally, because it's impossible to timeout or interrupt a call to
Do, I also added a DoContext method that takes a go Context, which is
also passed through to the called function.
2017-11-02 15:41:30 -07:00
John Brooks 0f47f62465 Return the new channel from RequestOpenChannel
This fixes a quirk where it would've been difficult to tell which of
several channels of the same type+direction is the one you just created.

It's also a fairly common pattern to want to interact with a channel
right after opening it; for example, a chat channel is opened and can
immediately send messages before getting the peer response. It's
convenient to not have to do a separate lookup.
2017-11-02 15:40:02 -07:00
John Brooks d19102b257 Pass channel handler directly to RequestOpenChannel
RequestOpenChannel is the primary API to open a new outbound channel. It
was written to take a connection.Handler and use OnOpenChannelRequest
to get a channels.Handler to represent the new channel, which is the
same path that inbound channels will take.

Going through the global OnOpenChannelRequest method makes this much
less flexible and prevents passing parameters to the new channel handler
during creation.  This also requires users of the API to know/find the
connection handler, or worse, to boilerplate one into existence for their
channel creation.

Instead, I think this function should take a channels.Handler directly,
so that the caller gets full control over the handler for their new
channel.

As part of that change, I've also moved the authentication logic in
AutoConnectionHandler to be contained entirely within
{In,Out}boundConnectionHandler.
2017-11-02 15:40:02 -07:00
John Brooks a62d1bbcc9 Improve ChatChannel API for message acknowledgement
ChatChannel didn't return the message ID for sent messages, which made
using the returned ACKs impossible. The SendMessage method now returns
the uin32 messageID.

Also, SendMessage didn't support the TimeDelta field for messages, which
is used for queued or resent messages. This is now available as
SendMessageWithTime.

And finally, the ChatMessageAck callback didn't indicate if mesasges
were accepted or not, which is part of the protocol. That was added as a
field, which is unfortunately a breaking API change, but I've made
enough of those lately to not feel guilty about it.
2017-09-25 13:04:21 -07:00
John Brooks ea788d58ef Don't use pointers to interfaces
There are few situations where a pointer to an interface is useful in
Go, and this isn't one. Interfaces can hold types by value or pointer,
so long as that type fulfills the interface.
2017-09-23 16:44:12 -06:00
Sarah Jamie Lewis 22cbf5d738 First Cut of Applications + Bugs, Formatting 2017-07-04 11:29:11 -07:00
Sarah Jamie Lewis 5d767174b1 Brand new API v0.2 2017-05-02 16:33:51 -07:00
John Brooks 860ae9a024 Rework the API around connection events
This is a rework of some parts of the API to make connection management
for applications more sane and reliable.

- The RicochetService interface is split into the ServiceHandler and
  ConnectionHandler interfaces. ServiceHandler is implemented by the
  application to handle inbound connections to a listener.
  ConnectionHandler is implemented to handle events for a single
  OpenConnection. Handler instances should no longer be shared for
  different listeners or connections.

- Instead of automatically starting a processConnection goroutine, the
  application is now responsible for calling OpenConnection.Process in a
  goroutine to act on the connection. This function blocks until the
  connection is closed. This change allows a better application pattern
  for setting the handler of a connection and reacting to connection
  loss.

- It is no longer necessary to have started a listener in order to make
  outbound connections.

- The Ricochet type is removed, because it no longer served any purpose,
  and this avoids having any shared state between different listeners or
  connections.
2016-12-03 16:53:13 -08:00
Sarah Jamie Lewis 630efa186e Fixing up EchoBot for golint 2016-11-08 15:12:50 -08:00
Sarah Jamie Lewis bfe5b74364 Refactor GoRicochet
* New Service Interface
* Server functionality
* 90% Code Coverage
* Regression Testing of Protocol Compliance
2016-07-02 18:52:28 -07:00
Sarah Jamie Lewis 93754f2916 Refactor to a move event-driven library - incomplete 2016-02-28 16:18:25 -08:00
Sarah Jamie Lewis a411fb8695 More consistent interfaces, better test coverage 2016-02-27 19:24:50 -08:00
Sarah Jamie Lewis 2353fc41e2 Refactor of APIs to make testing easier.
Also travis.ci integration
2016-02-27 16:20:40 -08:00
Sarah Jamie Lewis f684fd8694 Fleshing out error cases 2016-01-02 00:47:32 -08:00
Sarah Jamie Lewis 3469935bcb Adding examples 2016-01-01 18:08:28 -08:00