Ok I have been giving the networking some thought, now you may have to bear with me on this one as I have built a number of private n-tier client/server systems using .net sockets but never a public P2P one. (First time for everything eh.)
I believe I understand the principles though so let’s have a look...
How about a basic old style more or less unstructured P2P network? I did look for some open source C# P2P libraries but I couldn’t find any decent generic ones (found a good Java one though)
We don’t really need allot of the extra features these libraries come with anyway which tend to focus on file sharing, indexed searches and the like.
Anyway moving on...
When a peer connects they ask the peer they have connected to for their list of known active peers and add that list to their own in a local cache, however each peer only releases a small random selection of known peers (My feeble security attempt at stopping any one peer knowing too much about the whole network at any one time, plus it helps more evenly distribute connections) (Note: Knowledge shared about peers consists of a hostname (using a reverse DNS lookup), a port and no other information)
Now most of these will be behind NAT/firewalls and/or use dynamic IP address etc (Part of the reason for the reverse DNS lookup) so this does rely on most users opening up a port in their firewall and/or a few kind soles (or unwitting victims depending on how you look at it) opting to become ‘proxy nodes’ or ‘hubs’ which will involve that peer maintaining a few more sockets to deal with peers that cannot or won’t accept new connections. (Same for all IP based P2P networks AFAIK) Of course we can also look at HTTP socket tunnels there are lots of them out there or just build one in as a feature.
Each peer will maintain 4 ‘environment sockets’ one for up, down, left and right and if they have an open firewall port 4 ‘network sockets’, one listing socket for new connections and 3 directory sockets for dealing with discovery requests.
Connections on directory sockets will timeout after 60 seconds to keep them clear for new requests, since they are just used to propagate knowledge of the network to new peers, and should probably not accept new connections for say another 60 seconds to lessen the impact of a rouge peer running a DOS attack on the network.
A peer will have a node cache which will come with some built in default host names like darwinbots.com (I don’t mind putting one of my own personal domains in this list) and again I don’t mind having my personal server run a lightweight dedicated peer directory service that just hosts the 4 ‘network sockets’ and known active peer list (without any proxy or environment sockets) I.e. No heavy lifting.
These are only needed to seed entry to the network however since once a peer has connected it will now know about several more random peers that It can try to connect to (hence the cache approach) so if anyone leaves a peer running for any length of time they will become a good entry point for other peers, and in theory you could then withdraw the default entry points and the network would carry on... and then become self-aware, go by the name of ‘skynet‘ and take over the world with a species of bot it will call T-1000’s.
Anyway...
Upon connecting to the network it will walk though its list of fellow peers asking to hook up an environment socket, if the peer it has connected to is already full (or is not hosting an environment) it will proceed to the next in the list which of course will also transmit another set of random active peers which it can try.
When it does find a peer with an empty environment socket the connection will be transferred to that free socket and the two peers will be linked in one of the 4 directions.
The network will have 4 modes controlled by two flags 1) Evolution Mode and 2) Pond Mode
Don’t want too many as it will dilute the user base and only environments running the same mode can link. Organism migration rates, costs Brownian motion etc. can be set per peer to create diversity but some features will need to be locked to your environment mode such as gravity.
Standard enviroment (Petri dish style)
[attachment=1012:Networke..._Example.png]
Pond mode with gravity
[attachment=1013:Networke..._Example.png]
Err, don’t think I have forgotten anything... this post is getting far too long anyway.