#include <protocol.h>
Public Attributes | |
Public | |
Public members. | |
| char * | name |
| char * | version_str |
| void * | udata |
Private | |
Private members. | |
| void * | handle |
| Dataset * | hashes |
| Dataset * | features |
giFT Assigned Methods | |
Communication methods defined by giFT before protocol's initialization. No protocol should override these, however, most protocols will want to call at least some of these throughout the course of their protocol's lifespan. | |
| BOOL(* | init )(struct protocol *p) |
| int(* | trace )(struct protocol *p, char *file, int line, char *func, char *fmt,...) |
| int(* | tracesock )(struct protocol *p, TCPC *c, char *file, int line, char *func, char *fmt,...) |
| int(* | dbg )(struct protocol *p, char *fmt,...) |
| int(* | dbgsock )(struct protocol *p, TCPC *c, char *fmt,...) |
| int(* | warn )(struct protocol *p, char *fmt,...) |
| int(* | err )(struct protocol *p, char *fmt,...) |
| BOOL(* | hash_handler )(struct protocol *p, const char *type, int opt, HashFn algofn, HashDspFn dspfn) |
| void(* | support )(struct protocol *p, const char *feature, BOOL spt) |
| file_share *(* | share_lookup )(struct protocol *p, int command,...) |
| int(* | upload_auth )(struct protocol *p, const char *user, struct file_share *share, upload_auth_t *auth_info) |
| transfer *(* | upload_start )(struct protocol *p, struct chunk **chunk, const char *user, struct file_share *share, off_t start, off_t stop) |
| void(* | chunk_write )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source, unsigned char *data, size_t len) |
| void(* | source_abort )(struct protocol *p, struct transfer *transfer, struct source *source) |
| void(* | source_status )(struct protocol *p, struct source *source, enum source_status klass, const char *disptxt) |
| void(* | search_result )(struct protocol *p, struct if_event *event, char *user, char *node, char *href, unsigned int avail, struct file_share *file) |
| void(* | search_complete )(struct protocol *p, struct if_event *event) |
| void(* | message )(struct protocol *p, char *message) |
Protocol-specified Communication | |
These methods will be defined by your protocol at the time of Protocol::init. You should understand that you do not need to initialize all these values, as giFT will provide dummy implementations for them as to guarantee no method points to NULL. However, you should note that a failure to set certain key communication methods will result in a nearly worthless protocol plugin. | |
| BOOL(* | start )(struct protocol *p) |
| void(* | destroy )(struct protocol *p) |
| BOOL(* | download_start )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| void(* | download_stop )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source, int complete) |
| void(* | upload_stop )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| void(* | upload_avail )(struct protocol *p, unsigned long avail) |
| BOOL(* | chunk_suspend )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| BOOL(* | chunk_resume )(struct protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| BOOL(* | source_add )(struct protocol *p, struct transfer *transfer, struct source *source) |
| void(* | source_remove )(struct protocol *p, struct transfer *transfer, struct source *source) |
| BOOL(* | search )(struct protocol *p, struct if_event *event, char *query, char *exclude, char *realm, Dataset *meta) |
| BOOL(* | browse )(struct protocol *p, struct if_event *event, char *user, char *node) |
| BOOL(* | locate )(struct protocol *p, struct if_event *event, char *htype, char *hash) |
| void(* | search_cancel )(struct protocol *p, struct if_event *event) |
| void *(* | share_new )(struct protocol *p, struct file_share *file) |
| void(* | share_free )(struct protocol *p, struct file_share *file, void *data) |
| BOOL(* | share_add )(struct protocol *p, struct file_share *file, void *data) |
| BOOL(* | share_remove )(struct protocol *p, struct file_share *file, void *data) |
| void(* | share_sync )(struct protocol *p, int begin) |
| void(* | share_hide )(struct protocol *p) |
| void(* | share_show )(struct protocol *p) |
| int(* | stats )(struct protocol *p, unsigned long *users, unsigned long *files, double *size, Dataset **extra) |
Optional Protocol Communication | |
Methods which can (and probably should) be specified by each protocol, but will have sane and useful default implementations specified by giFT. Your protocol will not be adversely affected if you leave these values as is. | |
| int(* | source_cmp )(struct protocol *p, struct source *a, struct source *b) |
| int(* | user_cmp )(struct protocol *p, const char *a, const char *b) |
|
|
Browse an individual users content. The response to this event uses the same systems as a search.
|
|
|
Resume a suspended transfer. See Protocol::chunk_suspend. |
|
|
Suspend input/output on the specified chunk until resumed later. giFT uses these methods for managing transfer bandwidth usage (user-space throttling). Protocols should do their best to implement this.
|
|
|
Write data to the specified bidirectional chunk object. This is used for transfers when data has either been completely received or sent out (not considering kernel-level socket buffering). giFT will internally track transfer progress and/or write the necessary data to file.
|
|
|
Print debugging information to the appropriate logging channel. This data does not include information about the line that produced the log message. |
|
|
See Protocol::dbg and Protocol::tracesock. |
|
|
Cleanup everything you have initialized/allocated. This will generally mean that your protocol is being unloaded either by a giFT shutdown or by a simple unload directive to this specific protocol. |
|
|
Begin a new chunk transfer. Note that the protocol is not allowed to differentiate between multi-sourced and single-sourced transfers, you must simply obey what is specified by the chunk argument.
|
|
|
Cancel an active download. Protocols are expected to cleanup all sockets and internal data associated with this chunk. Please note that OpenFT violates this specification by attempting to use persisting HTTP connections for transfers.
|
|
|
Logging facility using the error log channel. |
|
|
Protocol features
|
|
|
lt_dlopen handle (NOTE: we cant use lt_dlhandle here because plugins depend on the size of this structure, but may not have lt_dlopen available!) |
|
|
Adds a new hashing algorithm handler for this plugin. Please note that while only one primary hashing routine may be specified, multiple secondary routines are allowed.
|
|
|
alternate index of hashes on a per-protocol basis |
|
|
Initialization function. This should not actually "start" the protocol, merely setup the Protocol structure passed. Note that giFT assigns this value before plugin initialization is called, and will always be set to your protocol's fully qualified case-sensitive name with the string literal "_init" appened to the ending. So, for OpenFT's case, this value will be set to OpenFT_init prior to the calling of said function.
|
|
|
Locate a file on the network by some unique content. See Protocol::browse and Protocol::search.
|
|
|
Deliver a raw message to the interface protocol.
|
|
|
protocol name |
|
|
Search request. Please note that Protocol::browse and Protocol::locate use the same result and completion routines as they are actually the same in giFT space.
|
|
|
Cancel a previously requested search.
|
|
|
Inform giFT that all search results that can be delivered have been delivered, or there is some reasonable reason to assume we have received the bulk of all results (if your protocol has no concept of clean search termination). This will "cancel" the search event gracefully and return to the interface protocol that your plugin has terminated. |
|
|
Send a search result from the plugin. This communication is used by the protocol when results need to be delivered to the interface protocol.
|
|
|
Add a new locally shared file to the network.
|
|
|
Destroy data returned by Protocol::share_new. |
|
|
Temporarily unshare all files. Some protocols (eg OpenFT) implement this with a single command disabling shares instead of removing them. To my knowledge, most other protocols will require you actually unshare every file manually. |
|
|
Lookup a locally shared file based on `command' criteria. This is the only interface to directly query the internally managed share cache. share = p->share_lookup (p, SHARE_LOOKUP_HASH, "MD5", md5sum, 16); I apologize for the relative lack of documentation provided for this function. Hopefully I will get around to it soon (boy do I say that a lot *grin*).
|
|
|
Allocate new protocol-specific data to be associated with file.
|
|
|
Remove a locally shared file from the network. See Protocol::share_add. |
|
|
Enable sharing after it was previously hidden. |
|
|
giFT has begun syncing shares. Expect Protocol::share_add and Protocol::share_remove calls until begin is FALSE, in which case the sync has completed. This is to be considered an effective modification of the current local shares and should be sent out over the socket if said protocol requires this.
|
|
|
Cancel a source as though the user had requested its removal. This is useful when your plugin knows (much better than giFT) that attempting to retrieve from this source is futile or that it could be dangerous. Please note that giFT has an internal automagic timeout for sources that do not have data throughput.
|
|
|
Notify a protocol about a new source being added to a transfer. This affects only downloads.
|
|
|
Compare two sources. This will be used when selecting how to manage multiple "similar" sources to a single transfer. The sources should compare equal (return value of 0) when it can be determined that they are the same user sharing the same file.
|
|
|
Remove all activity and pending data for the specified source. This method is used when giFT has been instructed to remove a source from the specified transfer (you may assume that this is a download), or when a transfer has completed all sources will be removed. |
|
|
Set the source status.
|
|
|
Start the protocol connections. See Protocol::init for a more detailed description as to why this separation was decided upon.
|
|
|
Request protocol statistics.
|
|
|
Add a protocol feature. This informs giFT of the various protocol/network-specific features this plugin can or can not successfully implement so as to modify giFT's behaviour. Currently, none of the feature-set defined by the default plugin (OpenFT) is actually used conditionally, however there will come a time when that is the case. For now it is probably safe just to ignore this. For a detailed list of supported options, see Protocol::features.
|
|
|
Method for producing informative log lines from within a protocol plugin. Do not use this function directly, see ::DBGFN instead. |
|
|
Special debugging method that will automatically format and display the peer information. This would not be provided unless I was pretty sure every plugin will use remote sockets <g>. |
|
|
arbitrary data associated by the plugin |
|
|
Inform giFT of a new upload request, specifically one which needs access to a locally shared object (that is, something in gift:/sharing/root). The return value from this function will help determine how the plugin should proceed.
|
|
|
Notify the protocol of upload availability changes. Protocols such as OpenFT take advantage of this by delivering to parent search nodes so that search results for other users can indicate the availability before download. Any protocol that has no concept of upload eligibility/availability, can safely ignore this.
|
|
|
Inform giFT of a new upload which is about to begin. Please note that this does not tackle authorization of the share and in fact allows subversion of that entire system if you so wish. For normal uploads you will definitely want to obey the auth rules so I highly suggest calling and properly handling Protocol::upload_request prior to using this method.
Share::path Share::mime Share::size You must also set a valid hash for the primary registered hashing algorithm for your plugin.
|
|
|
|
Compare two users. This was specially added for OpenFT so that node aliases could be weeded out as a significant portion of the username field. Default implementation here is a simple strcmp. |
|
|
protocol version, will be shown by giFT -V |
|
|
Logging facility using the warning log channel. |
1.3.7