Hey Remy,
First of all, let me thank you for your time spent answering my not so well formulated question. I could've made a better job in defining my needs, that's for sure.
TCP makes a clear distinction between client (connect) and server (listen+accept) socket connections. But P2P doesn't. A peer may need to connect out to another peer, or be connected to by another peer. So you have to be prepared to handle both cases.
You're absolutely correct in this.
My naive idea is to have the connect to, or what I call DOWN connections be handled by the usual Server methods of Listen+Accept.
Those would be added to a list that will contain both the UP(initiated) and DOWN(received) connections, with a flag attached to the connection so we know if it's an UP or DOWN one.
Then add some methods to allow for the programmer to feed the component, either a single or multiple addresses for the component to initiate connections, and add them to the common list properly flagged.
One thing I forgot to mention is that in a P2P model in the context of crypto, all connections are forever. These are the type of always on, as long as nothing goes wrong, or until the node quits.
Not sure if this influences anything. In a way, we could kinda compare them to websockets, kinda.
You are probably looking for the TIdSimpleServer component, which is a simple non-threaded TCP server that accepts only 1 client connection at a time. For example, TIdFTP uses TIdTCPClient for Passive mode (outbound) transfers, and TIdSimpleServer for Active mode (inbound) transfers. It chooses which component to use for a transfer, but the bulk of the transfer logic is the same regardless of which component is used to create the connection.
You can use a similar approach in a P2P scenario.
Hummm... Non-threaded is probably not the best solution since a lot of parallel tasks must be performed while the
P2P peer code is also doing it's thing.
Nonetheless those are good hints on trying to investigate a solution for my dilemma.
Now, let's say I would take upon myself the task to create such a thing:
- Can you please point me at the best LEGO pieces I could use, mainly in terms of the connection list and the connection data classes?
- Can you please point me at the best implementation of the Listen+Accept code in any of the current Server implementations?
- Can you suggest some bullet points on how I could then apply some thoughtful glue to all this?
Again, so many thanks in advance for any answer you may provide.
Cheers,
Gus