Skip to content

TCP socket rewrite with strand and queueing support#1938

Merged
clemahieu merged 7 commits intonanocurrency:masterfrom
cryptocode:tcp/strand
May 14, 2019
Merged

TCP socket rewrite with strand and queueing support#1938
clemahieu merged 7 commits intonanocurrency:masterfrom
cryptocode:tcp/strand

Conversation

@cryptocode
Copy link
Copy Markdown
Contributor

@cryptocode cryptocode commented Apr 26, 2019

Marking as incomplete as more docs and discussions related to the needs for implementing tcp live messages are needed.

  • Factored out socket stuff from bootstrap
  • Introduced server_socket since it's no longer bootstrap specific (though bootstrap still starts the tcp server, a different PR should refactor that)
  • Socket multithreading support through write queues and strands
  • Write queue means shared_ptr of buffers is required everywhere (to extend buffer lifetime). send_buffer_raw removed for that reason.
  • Socket can be single-writer (default for now) or multi-writer. Former is slightly more efficient (suitable for bootstrap connections which is send/reply), while the latter allows concurrent writers (for live messages if we end up not awaiting replies like with UDP)
  • Checkup and the two timer variables are replaced with a steady deadline timer
  • Added stats for accept success/failures as an accept failure log entry may give the impression that the node has stopped accepting tcp connections even though a timeout will ensure stale connections are dropped.
  • Added network_timeout as a logging option. This was previously tied to bulk pull logging which doesn't make sense for live messages.
  • tcp_client_timeout renamed to tcp_io_timeout. Proposing to increase from 5 to 15 second in case tunnels need to be established etc (5 sec may be a tad too low, causing unnecessary connection timeouts)
  • tcp_server_timeout removed, no longer needed as accept always starts a timer
  • tcp_idle_timeout added, default socket idling timeout, can be overridden by constructor
  • Removed if (!ec) from callback wrappers, in case callback needs notification of errors/do corrective actions/logging.
  • Fix io_ctx#run race in wallet. Thread runner is now started first. This requires a work token, which is cancelled on join.
  • To enable tests with thread_runner to finish more quickly, join takes an argument where event looping can be stopped
  • remote is cached on connect/accept as it's not thread safe to call it directly (caching is more convenient than wrapping in a strand on use sites). For outgoing connections, the remote endpoint is known. For accept, there's an overload to receive it.
  • In testutils, a completion_signal type is added. Some tests will benefit from using thread runner instead of polling (the new socket test is an example) and this class simplifies waiting for async operations to complete.

@cryptocode cryptocode added incomplete This item is incomplete and should not be merged if it is a pull request networking labels Apr 26, 2019
@cryptocode cryptocode added this to the V19.0 milestone Apr 26, 2019
@cryptocode cryptocode self-assigned this Apr 26, 2019
@zhyatt zhyatt requested review from SergiySW, clemahieu and wezrule and removed request for wezrule April 30, 2019 14:42
@cryptocode cryptocode removed the incomplete This item is incomplete and should not be merged if it is a pull request label Apr 30, 2019
@cryptocode
Copy link
Copy Markdown
Contributor Author

If merged, update wiki docs wrt config changes

@cryptocode cryptocode added the documentation This item indicates the need for or supplies updated or expanded documentation label Apr 30, 2019
@clemahieu clemahieu merged commit 381fbcd into nanocurrency:master May 14, 2019
SergiySW added a commit that referenced this pull request May 22, 2019
- merge_peer function modified to try TCP connection before UDP
- TCP channels ongoing_keepalive function used to wake up long not sending channels to prevent TCP disconnection from server
- Live TCP connection starts with node ID handshake
- After handshake node sends preferred peering ports for response channels (keepalive self)
- Received TCP live message is responded to sender with response channels
- Using #1938 multi-writer for TCP channel
- Multiple nodes system () tests using TCP connections by default
- Some tests modified to check 2 live network options: TCP connections & UDP connections
- tcp_incoming_connections_max added, max established incoming TCP connections
- bootstrap_server modified to accept live network messages
@zhyatt zhyatt removed the documentation This item indicates the need for or supplies updated or expanded documentation label Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants