Skip to content

Commit

Permalink
Simplify Peer receive action
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jul 10, 2023
1 parent 2837da6 commit f93f646
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public Connection connectToPeer(InetSocketAddress hostAddress) {
if ((existing!=null)&&!existing.isClosed()) return existing;
synchronized(connections) {
// reopen with connection to the peer and handle server messages
newConn = Connection.connect(hostAddress, server.peerReceiveAction, server.getStore(), null,Config.SOCKET_PEER_BUFFER_SIZE,Config.SOCKET_PEER_BUFFER_SIZE);
newConn = Connection.connect(hostAddress, server.receiveAction, server.getStore(), null,Config.SOCKET_PEER_BUFFER_SIZE,Config.SOCKET_PEER_BUFFER_SIZE);
connections.put(peerKey, newConn);
}
} catch (IOException | TimeoutException e) {
Expand Down
17 changes: 2 additions & 15 deletions convex-peer/src/main/java/convex/peer/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,7 @@ public class Server implements Closeable {
* Message Consumer that simply enqueues received client messages received by this peer
* Called on NIO thread: should never block
*/
Consumer<Message> clientReceiveAction = m->processMessage(m);

/**
* Message Consumer that simply enqueues received messages back from outbound peer connections
* Called on NIO thread: should never block
*/
Consumer<Message> peerReceiveAction = msg-> {
// We prioritise missing data requests from a Peer we have connected to
if (msg.getType()==MessageType.MISSING_DATA) {
handleMissingData(msg);
} else {
processMessage(msg);
}
};
Consumer<Message> receiveAction = m->processMessage(m);

/**
* Connection manager instance.
Expand Down Expand Up @@ -775,7 +762,7 @@ public HashMap<Keyword, Object> getConfig() {
* @return Message consumer
*/
public Consumer<Message> getReceiveAction() {
return clientReceiveAction;
return receiveAction;
}

/**
Expand Down

0 comments on commit f93f646

Please sign in to comment.