#include <gi_protocol.h>
Public Attributes | |
Public | |
Public members. | |
| char * | name |
| char * | version |
| void * | udata |
Private | |
Private members. | |
| bool | active |
| void * | handle |
| GiDataset * | hashes |
| GiDataset * | 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 gi_protocol *p) |
| int(* | trace )(struct gi_protocol *p, const char *file, unsigned int line, const char *funcname, int level, const char *fmt,...) GI_PRINTF_ATTR(6 |
| int(* | tracesock )(struct gi_protocol *p, GiTcp *conn, const char *file, unsigned int line, const char *funcname, int level, const char *fmt,...) GI_PRINTF_ATTR(7 |
| int(* | dbg )(struct gi_protocol *p, int level, const char *fmt,...) GI_PRINTF_ATTR(3 |
| int(* | dbgsock )(struct gi_protocol *p, GiTcp *conn, int level, const char *fmt,...) GI_PRINTF_ATTR(4 |
| int(* | warn )(struct gi_protocol *p, int level, const char *fmt,...) GI_PRINTF_ATTR(3 |
| int(* | err )(struct gi_protocol *p, int level, const char *fmt,...) GI_PRINTF_ATTR(3 |
| bool(* | hash_handler )(struct gi_protocol *p, struct gi_hash_handler *handler) |
| void(* | support )(struct gi_protocol *p, const char *feature, bool spt) |
| gi_file_share *(* | share_lookup )(struct gi_protocol *p, int command,...) |
| int(* | upload_auth )(struct gi_protocol *p, const char *user, struct gi_file_share *share, upload_auth_t *auth_info) |
| transfer *(* | upload_start )(struct gi_protocol *p, struct chunk **chunk, const char *user, struct gi_file_share *share, off_t start, off_t stop) |
| void(* | chunk_write )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source, unsigned char *data, size_t len) |
| void(* | source_abort )(struct gi_protocol *p, struct transfer *transfer, struct source *source) |
| void(* | source_status )(struct gi_protocol *p, struct source *source, enum source_status klass, const char *disptxt) |
| void(* | search_result )(struct gi_protocol *p, void *event, const char *user, const char *node, const char *href, unsigned int avail, struct gi_file_share *file) |
| void(* | search_complete )(struct gi_protocol *p, void *event) |
GiProtocol-specified Communication | |
These methods will be defined by your protocol at the time of GiProtocol::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 gi_protocol *p) |
| void(* | stop )(struct gi_protocol *p) |
| void(* | destroy )(struct gi_protocol *p) |
| bool(* | download_start )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| void(* | download_stop )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source, int complete) |
| void(* | upload_stop )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| void(* | upload_avail )(struct gi_protocol *p, unsigned long avail) |
| bool(* | chunk_suspend )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| bool(* | chunk_resume )(struct gi_protocol *p, struct transfer *transfer, struct chunk *chunk, struct source *source) |
| bool(* | source_add )(struct gi_protocol *p, struct transfer *transfer, struct source *source) |
| void(* | source_remove )(struct gi_protocol *p, struct transfer *transfer, struct source *source) |
| bool(* | search )(struct gi_protocol *p, const void *event, const char *query, const char *exclude, const char *realm, GiDataset *meta) |
| bool(* | browse )(struct gi_protocol *p, const void *event, const char *user, const char *node) |
| bool(* | locate )(struct gi_protocol *p, const void *event, const char *htype, const char *hash) |
| void(* | search_cancel )(struct gi_protocol *p, void *event) |
| void(* | share_sync_begin )(struct gi_protocol *p) |
| void(* | share_sync_end )(struct gi_protocol *p) |
| void(* | share_add )(struct gi_protocol *p, struct gi_file_share *file) |
| void(* | share_remove )(struct gi_protocol *p, struct gi_file_share *file) |
| void(* | share_hide )(struct gi_protocol *p) |
| void(* | share_show )(struct gi_protocol *p) |
| int(* | stats )(struct gi_protocol *p, unsigned long *users, unsigned long *files, double *size, GiDataset **extra) |
Optional GiProtocol 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 gi_protocol *p, struct source *a, struct source *b) |
| int(* | user_cmp )(struct gi_protocol *p, const char *a, const char *b) |
|
|
For all time between a call to p->start and p->stop, active will be true; otherwise, false |
|
|
Browse an individual users content. The response to this event uses the same systems as a search.
|
|
|
Resume a suspended transfer. See GiProtocol::chunk_suspend. |
|
|
Suspend input/output on the specified chunk until resumed later. giFT uses these methods for managing transfer bandwidth usage (user-space throttling). GiProtocols 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 GiProtocol::dbg and GiProtocol::tracesock. |
|
|
Prepare your plugin to be unloaded via the dynamic loading infrastructure. All hooks into giftd's event loop should be removed, and all memory should be freed.
|
|
|
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. GiProtocols 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. |
|
|
GiProtocol features
|
|
|
lt_dlopen handle (NOTE: We can't 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 GiProtocol 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 GiProtocol::browse and GiProtocol::search.
|
|
|
Protocol name |
|
|
Search request. Please note that GiProtocol::browse and GiProtocol::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 it is reasonable 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.
|
|
|
Notification that a new locally shared file is available. When the daemon first starts up, and after the plugins have been loaded (but not necessarily started with GiProtocol::start), all shares found in the ~/.giFT/shares database will be given an individual call to this function in order to register it for the first time to plugins. After that, only synchronization requests will be capable of calling upon this interface.
|
|
|
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*).
|
|
|
Notification that a previously shared object is no longer available to this plugin. This does not necessarily imply that the file has been removed by the user and is thus not available on disk, simply that your plugin is no longer allowed to share it, or associate user data.
|
|
|
Enable sharing after it was previously hidden. |
|
|
This message notifies your plugin that the daemon is preparing to make changes to the local share index. Within the window of a call to GiProtocol::share_sync_begin and GiProtocol::share_sync_end, you should be expected to process and handle GiProtocol::share_add and GiProtocol::share_remove requests. Modifications to the share index may never occur outside of the context of this notification. |
|
|
See ::share_sync_begin. |
|
|
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 GiProtocol::init for a more detailed description as to why this separation was decided upon.
|
|
|
Request protocol statistics.
|
|
|
Stop protocol connections and release any input/timer events. This operation is usually performed when giftd has been asked to disable the protocol plugin, but not unload it. |
|
|
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 GiProtocol::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. GiProtocols 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 GiProtocol::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