TrustPeer Prototype Internal Architecture

Here is a draft describing the main lines of TrustPeer Prototype internal software architecture

The main parts:

- int tp_get(const char * local_filename,const char * remote_filename,const int* conn_ports): Get file from the other peers 

-  int tp_search(const char * keywords,char ** results,const int* conn_ports): Search for file names from the other peers
This can share code parts (client sockets) with tp_get()
"results" is several ansi strings stored in the heap malloc(), the caller must call free(*results) when he's done! (memory leak warning)
a result is 2 strings: a filename then a size
in order to be simple, only the file sizes will be sent, but no checksum yet
the last string will be "", indicating all the results have been read (overflow warning)

ANSI C buffer overflow warning: remember that when you build an ANSI string (char * or char **) you must end it with a null char (ASCII 0) !

- int tp_server(GTcpSocket* server), uses the already opened server socket and uses processes/threads to receive requests from other peers, answer them, and forward them if they can not be answered with local datas
This can use tp_get() and tp_search() to forward received requests
all shared files will be in the shar/ directory
in order to be simple, only one process/thread can be launched

- int main(int argc, char** argv): launches a server socket that will be used to communicate with plugins: the port # can be stored in local "int server_port"
this port is given in argv when launching trustpeer, and can be slightly incremented if needed
the second arg is the number of connexions that are to be launched
main() launches the connexions (plugins) at the start
all the connexion files are located in the conn/ directory
all the plugins are located in the plug/ directory
each connexion_file should begin with the plugin_name to be launched, then the version # of the file struct

main() stores the plugins local server ports in local "int* conn_ports", 0 ends this array (overflow warning)


then main() can launch tp_server()

then main() asks the user for filenames and keywords , it uses tp_get() and tp_search() to answer !

Remember that each part should have its own .h, and should use "static" for private functions and variables (variables that are outside functions. You should never use "static" inside a function since it is not threadsafe)