Commit Graph

109 Commits

Author SHA1 Message Date
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
Sarah Jamie Lewis 1ed9265866
Merge pull request #31 from special/fix/pointers-to-interfaces
Don't use pointers to interfaces
2017-11-02 14:32:55 -07:00
Sarah Jamie Lewis ec16eee2aa
Merge pull request #29 from special/fix/create-outbound-conn
Make NegotiateVersionOutbound a public function
2017-11-02 14:31:42 -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
John Brooks 41d9401ca4 Make NegotiateVersionOutbound a public function
This is needed to allow creating a Connection for an arbitrary
application-provided io.ReadWriteCloser, instead of doing network logic
inside of go-ricochet. ricochet-go does its own connection management.

I would rather rework this API so that Connection has two construct
methods, inbound and outbound, that do version negotiation and are
always used. The methods that do networking and construct a Connection
would then be a separate (and non-root) package building on top of that.
2017-09-19 14:19:06 -06:00
Dan Ballard f04239c885 make echobot use new SetupOnion 2017-09-04 20:33:21 -07:00
Sarah Jamie Lewis d2dceef028 Merge pull request #26 from dballard/crypto-utils
Add more crypto/utils and extend SetupOnion to support unix sockets
2017-08-15 11:34:26 -07:00
Dan Ballard 5937ceee73 Add more crypto/utils and extend SetupOnion to support unix sockets 2017-08-14 08:43:33 -07:00
Sarah Jamie Lewis 93baafc2f7 Adding bulb to godep 2017-08-05 12:48:25 -07:00
Sarah Jamie Lewis 22cbf5d738 First Cut of Applications + Bugs, Formatting 2017-07-04 11:29:11 -07:00
Sarah Jamie Lewis 1cf7c2b7c7 Adding a Trace log to Connection and removing all other logging directives 2017-06-27 12:48:35 -07:00
Sarah Jamie Lewis f4ed1c244b Adding Inbound Version Negotiation
+ Error handling for missing private key setting
2017-06-27 10:39:33 -07:00
Sarah Jamie Lewis a2fa40492a Merge pull request #22 from dballard/patch-1
fix typo
2017-06-10 20:18:11 -07:00
Sarah Jamie Lewis 4f1a2f82cc Merge pull request #21 from dballard/new_api-fix_app
fix syntax errors
2017-06-10 20:17:58 -07:00
Dan Ballard d895b46a03 fix typo 2017-06-10 16:19:56 -07:00
Dan Ballard 6f07cff0bc fix syntax errors 2017-06-10 15:20:41 -07:00
Sarah Jamie Lewis 5d767174b1 Brand new API v0.2 2017-05-02 16:33:51 -07:00
Sarah Jamie Lewis 5a720a08d0 Merge pull request #17 from special/api-handlers
Rework the API around connection events
2017-01-15 15:49:09 -08: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 9d6592e1e4 Fixing up some comments 2016-11-08 15:05:05 -08:00
Sarah Jamie Lewis c37f9008b6 gofmt simplify 2016-11-08 14:55:17 -08:00
Sarah Jamie Lewis 985e7d3c5c Update README.md 2016-11-08 14:45:51 -08:00
Sarah Jamie Lewis 13b2f9111d Counting main package in tests 2016-11-08 14:42:58 -08:00
Sarah Jamie Lewis 779dabed9c Fixing spelling 2016-11-08 14:40:38 -08:00
Sarah Jamie Lewis 00b636bf9d Updating travis 2016-11-08 14:14:57 -08:00
Sarah Jamie Lewis cfc7dc243c Add script for coveralls 2016-11-08 14:11:21 -08:00
Sarah Jamie Lewis a7c8ec5b0e Update README.md 2016-11-08 13:54:45 -08:00
Sarah Jamie Lewis 8c4ef5617b Merge pull request #14 from laanwj/2016_11_request_stop_message_loop
Make it possible to request stop of message loop
2016-11-08 13:51:40 -08:00
Wladimir J. van der Laan 5e3e873a16 networkresolver: fix gofmt output 2016-11-03 17:35:10 +01:00
Wladimir J. van der Laan c16dce9f60 Make it possible to request stop of message loop
Add a `RequestStopMessageLoop()` method to `Ricochet` to be able to
stop handling new connections. Right now, ProcessMessages is an infinite
loop.
2016-11-03 17:30:38 +01:00
Sarah Jamie Lewis f2788c929f Updating Travis CI config
Also removing Makefile
2016-10-02 18:02:40 -07:00
Sarah Jamie Lewis 0de7b76cbc Replacing proxy dependency with golang.org/x/net/proxy 2016-10-02 17:49:12 -07:00
John Brooks 47ba383334 Improve packet-layer buffering and parsing logic
SendRicochetPacket now has error handling, correctly encodes channel
ids, accepts any io.Writer, and ensures that all data is written. All
callers should be changed at some point to handle errors also.

RecvRicochetPackets is refactored to return only one packet per call and
avoid reading more data than it will consume, which simplifies the logic
and fixes a number of problems with short reads or large packets. Also
fixed an error in bounds checking that caused a remote panic for invalid
packet sizes. It also now accepts any io.Reader.

Tests are updated and expanded, and now pass.

Changes to Ricochet.processConnection are whitespace-only, because of
the removal of the inner packets loop.
2016-10-02 17:49:12 -07:00
John Brooks cc50e0dfe9 Fix buffering in version negotiation
The service-side version negotiation had a buffer overread that would
cause remotely triggerable panic.

Refactor that code to resolve that issue, follow the spec more exactly,
and avoid reading more data from the socket than is used for version
negotiation, in case clients write optimistically.
2016-10-02 17:49:12 -07:00
John Brooks 1c317fc186 Add OnDisconnect event 2016-10-02 17:49:12 -07:00
John Brooks 733e00d6f9 Set OpenConnection.OtherHostname after successful auth proof 2016-10-02 17:49:12 -07:00
John Brooks f6d6991f46 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.
2016-10-02 17:49:12 -07: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 5b013a76c3 Update README.md 2016-02-27 19:42:23 -08:00
Sarah Jamie Lewis 7837ad12ab Adding coverage stats to travis output 2016-02-27 19:28:54 -08:00
Sarah Jamie Lewis ad69913be9 Formatting 2016-02-27 19:26:43 -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 91036c918d Fixing up some error handling 2016-01-05 20:42:49 -08:00
Sarah Jamie Lewis 04f99b298f Cleaning up error handling
Getting rid of lots of FATALs, now they can be handled by the calling
function.
2016-01-04 19:53:10 -08:00
Sarah Jamie Lewis 97f5982754 Adding ability to check contact is known 2016-01-03 15:33:10 -08:00
Sarah Jamie Lewis f684fd8694 Fleshing out error cases 2016-01-02 00:47:32 -08:00