1
Source code (src/httpserver.cpp):
static void ThreadHTTP(struct event_base* base, struct evhttp* http)
{
RenameThread("bitcoin-http");
LogPrint("http", "Entering http event loop\n");
event_base_dispatch(base);
// Event loop will be interrupted by InterruptHTTPServer()
LogPrint("http", "Exited http event loop\n");
}
Can anyone help me understand this portion of logic? In particular
- What is the HTTP magic happening here
event_base_dispatch(base)? - Why are we renaming threads?
Thanks for the clear explanation! As I understand, here we are registering handlers while we are listening to socket connections. But where is the logic which actually causes the invocation of these callback functions? Lets say, I have established connection between 2 nodes
AandBand I want to send aINVmessage fromBtoA. – Paarth – 2015-12-16T04:06:57.330@Paarth
But where is the logic which actually causes the invocationSomewhere in libevent, I think. I don't think I understand your question.Lets say, I have established connectionThat's not handled by this code at all. This is JSON-RPC code, and you're looking for the peer to peer code. That's in ProcessMessage in main.cpp on the receiving side, and SendMessages in main.cpp on the sending side. Look forNetMsgType::INV– Nick ODell – 2015-12-16T06:39:50.763Thank you once again. So JSON-RPC is used ONLY for communicating between bitcoin-d servers and its client? But the mining nodes individually talk via some other logic to exchange messages (like inv, ack or blk ) etc – Paarth – 2015-12-17T05:31:42.360
1) Yes. 2) Yes, but ack and blk aren't messages. The closest thing in the p2p protocol to ack and blk is
pongandblock. – Nick ODell – 2015-12-17T05:44:54.367Really sorry to bother you again. My background in networks is pretty bad. But where exactly is the socket connection happening for p2p protocol? All the logic I can see in codebase is associated with JSON-RPC in
httpserver.cpp. Themain.cppyou had pointed out implicitly boils down to overloaded functionPushMessage, which usesBeginMessageinnet.cpp. The logic am looking for is how the data inPushMessage(orBeginMessage) is actually being sent to other nodes. It needs to send the data via some opened socket right? If I am not wrong. – Paarth – 2015-12-17T11:05:02.2671
@Paarth The connection is opened here: https://github.com/bitcoin/bitcoin/blob/7a5040155ed59f8c9c51734bb2ee29f1593eaa6a/src/net.cpp#L1615 The data is sent here: https://github.com/bitcoin/bitcoin/blob/7a5040155ed59f8c9c51734bb2ee29f1593eaa6a/src/net.cpp#L764
– Nick ODell – 2015-12-17T18:39:55.230