Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code cleanup, 100% compliant with checkfiles.pl now :D
- Loading branch information
Caleb James DeLisle
committed
Apr 15, 2012
1 parent
eff7285
commit 92bce3a
Showing
27 changed files
with
292 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef DHTMessage_H | |||
#define DHTMessage_H | |||
|
|||
#include "benc/Dict.h" | |||
|
|||
/** | |||
* Maximum number of bytes in a message. | |||
* Ethernet MTU is 1500 so it's hard to imagine much more. | |||
*/ | |||
#define DHTMessage_MAX_SIZE 1536 | |||
|
|||
|
|||
/** | |||
* This struct represents a DHT message which will be passed to the | |||
* modules. The only part of the message which will be available to | |||
* all modules is Message.peer. Incoming modules will have Message.bytes | |||
* and Message.length when they come from the network module. | |||
*/ | |||
struct DHTMessage; | |||
struct DHTMessage | |||
{ | |||
struct Address* address; | |||
|
|||
char padding[512]; | |||
|
|||
/** The message in binary format. */ | |||
char bytes[DHTMessage_MAX_SIZE]; | |||
|
|||
/** The length of the binary message. */ | |||
unsigned short length; | |||
|
|||
/** The message as a bencoded dictionary. */ | |||
Dict* asDict; | |||
|
|||
/** | |||
* If this message is an outgoing reply, replyTo is the original query. | |||
* For incoming replies or any queries, it is NULL. | |||
*/ | |||
struct DHTMessage* replyTo; | |||
|
|||
/** A memory allocator which will be freed after this message is sent. */ | |||
const struct Allocator* allocator; | |||
}; | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef DHTModule_H | |||
#define DHTModule_H | |||
|
|||
#include "dht/DHTMessage.h" | |||
|
|||
/** | |||
* This represents a DHT module. | |||
* Pass one of these to DHTModule_register() and it | |||
* will handle dht requests and responses. | |||
*/ | |||
struct DHTModule; | |||
struct DHTModule { | |||
/** | |||
* A user friendly null terminated string which will be used to | |||
* manipulate the module using the DHTModules API. | |||
*/ | |||
const char* const name; | |||
|
|||
/** | |||
* The module's state. | |||
*/ | |||
void* const context; | |||
|
|||
/** | |||
* @param the message which came in from a peer. | |||
* @param context the module's state. | |||
* @return 1 if a response should be sent for this message. | |||
* -1 if the message is known invalid and should not be passed | |||
* to any more handlers. | |||
*/ | |||
int (* const handleIncoming)(struct DHTMessage* message, | |||
void* context); | |||
|
|||
/** | |||
* @param message the message which will be sent to the peer. | |||
* @param context the module's state. | |||
* @return -1 if the message should not be propigated to any more modules. | |||
* use with caution as it may be interpreted as network loss. | |||
*/ | |||
int (* const handleOutgoing)(struct DHTMessage* message, | |||
void* context); | |||
}; | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.