|
||||||||||||
P2P NetworksScoundrel has been designed with the intention of making the addition of more peer2peer networks easy. The p2p-unit defines the basic behaviour needed from an implementation in order for Scoundrel to be able to use it and also adds some support functionality. Currently, the design is not sufficiently stable to encourage the development of custom networks. The major milestone left to pass is the issue of sharing and how it is to be implemented. There is an embryo of a design of this in the TP2PNetwork-class, but it is definetely going to change. Also, the handling of features such as advanced (not string-only) searching, the queueing of queries and manual searching has not been ironed out. However, the basic steps for creating a custom network will not change, only the interface such an implementation needs to support. Other issuesThe original intention was to put the network implementations into dll's separate from the Scoundrel-executable. However, some problems handling TFrames in dll's showed up, so that idea has for the moment been set aside. Once the problems are resolved, it should however require very little effort to put the network implementations in separate dll's. There is another issue with the custom networks: It will only be possible to implement them in Delphi. Now, don't get all upset about this. Delphi is a nice and easy to use language/development tool. You might even want to learn it if you don't already know it. The only way around this that I can think of is to create a wrapper class and through it allow networks to be implemented through COM-objects. I however know too little of COM to implement this myself. Now that we know the problems and limitations, lets get to how its done: How to create a custom P2P networkForum - please post any questions you have regarding the implementation of custom networks in the network forum. Scoundrel handles custom networks through one unique entry point. This is the TP2PNetworkManagerFactory-class. From this class, it creates instances of (subclasses to) the TP2PNetworkManager-class. Reading the source, you notice that the TP2PNetworkManager-class has two interesting functions: GetNetworkInstance (returning an instance of TP2PNetwork) and GetNetworkConfigurator (returning an instance of TFrame). The TP2PNetwork-class at the moment has these interesting methods:
procedure Tick;virtual;
procedure Login;virtual;abstract;
procedure Logoff;virtual;abstract;
procedure Search(query : String);overload;virtual;abstract;
procedure Get(sr : TP2PSearchResult);virtual;abstract;
procedure Abort(sr : TP2PSearchResult);virtual;abstract;
function CanSearch:boolean;virtual;abstract;
function CanDownload(SearchResult : TP2PSearchResult):boolean;virtual;abstract;
Remember that this interface is not frozen. Changes not only can, but will be made to it. Tick - This is the basic heartbeat of the application, the procededure is called once every second, to allow the network to timeout downloads and searches and whatnot. Login/Logoff/Search. Pretty basic Get/Abort: Get the file/abort the download associated with the TP2PSearchResult. CanSearch/CanDownload. Always called before a Search or Get command. There are also a bunch of events that need to be triggered at the right times. These are pretty self-explanatory, check out the napster-implementation if you want to know more about them. Anyway, the TP2PSearchResult-class need a few words. When searching, the network returns search results through an event. These results must be subclasses of TP2PSearchResult. Store any information you need for the search results in this class. There are a couple of rules that the classes must adhere to, as well as some promises that Scoundrel makes to the networks. That'll all get documented one day, when the napster-implementation is "complete". Class summary
|