User talk:Storkme

SYI Share will be a hybrid-p2p network based on the Gnutella protocol.

= Terminology = Yeah, I stole the terms off bittorrent, gtfover it.
 * Swarm - Collection of peers sharing a particular file
 * Peer - a client connected to the network
 * Visible - are ports forwarded correctly to allow incoming streams

= Protocol = The protocol will be heavily based on Gnutella, since that's wicked popular and seems to work well. The main difference is this one will use a centralized server.
 * Upon connection to the centralized server (after authentification) a few checks are ran on the client host:
 * Check if port forwarding for TCP connections works.
 * Perform a UDP hole punch for recieving queries.
 * Following that, one of the following steps will be taken:
 * If the peer is visible, the server instructs some other peers to connect to this one.
 * If the peer is invisible, the server gives a list of peers
 * The above steps are repeated to maintain a set number of active peers.

Searching
I have come up with an overview of search methods. Using a compromise between a Distributed Search & a Partially Centralized Search. For example, if the number of peers online is under 150, the peer uses a P.C. search. Otherwise, a D. Search is used.

Downloading
So far an unresolved issue. From a list of peers we can download from, we have to somehow max out our download speed.

= Server =

Networking
The server will use conventional IO for now, because I don't know NIO very well.
 * All sockets have a 10,000ms connect timeout.
 * All sockets have a 30,000ms read timeout.

Goals
The server is responsible for a number of things:
 * Handling peer login. i.e., authentification using the given username and password hash, loading files the peer is willing to share (including file name + size).
 * Maintaining peer status and keeping peers updated with status of other peers.
 * Maintaining a list of swarms and the clients attatched to them, so when a user requests a particular file the server adds them to the swarm update list so every peer in the swarm knows what's going on.
 * Handle chunk requests from peers.

Ideas
ServerSocket serv = new ServerSocket(Config.getInt("Listen Port")); while(!serv.isClosed) { unauthedConnections.add(serv.accept); }
 * Entry class: Server. Responsible for loading configuration and waiting for peers to connect. A new UnauthedConnectionQueue (thread (daemon)) is created to handle incoming connections. Each time a connection is accepted the Socket is added to the Queue and handled a while loop in the run method of UnauthedConnectionQueue.
 * Advantages: Less threads means it'll run better and we don't have to create a Peer object in a new thread to handle authing that needs to be disposed.
 * When created, the Peer calls PeerHandler.addPeer(this) to add itself to the PeerHandler. The PeerHandler has a synchronized ArrayList which sends ping packets every 30 seconds. The PeerHandler also lets peers know when peers have connected/disconnected.

= Packet Structure =
 * One byte (unsigned) for packet ID
 * Four bytes (unsigned) for payload length
 * Variable bytes for the payload