You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(5) |
Nov
|
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(13) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <tar...@pd...> - 2005-01-15 03:12:08
|
Author: tarcieri Date: 2005-01-14 19:53:17 -0700 (Fri, 14 Jan 2005) New Revision: 212 Added: hub/TransactionManager.c hub/TransactionManager.h Modified: hub/Makefile.in hub/PieceServer.c hub/ServerManager.c hub/main.c hub/servertxn.c Log: Fixed botched commit for hub TransactionManager code Modified: hub/Makefile.in =================================================================== --- hub/Makefile.in 2005-01-15 02:40:59 UTC (rev 211) +++ hub/Makefile.in 2005-01-15 02:53:17 UTC (rev 212) @@ -9,9 +9,9 @@ FileHashes.o \ FileManager.o \ PieceServer.o \ - ReplyManager.o \ Server.o \ ServerManager.o \ + TransactionManager.o \ VFSMonitor.o \ main.o \ netevent.o \ Modified: hub/PieceServer.c =================================================================== --- hub/PieceServer.c 2005-01-15 02:40:59 UTC (rev 211) +++ hub/PieceServer.c 2005-01-15 02:53:17 UTC (rev 212) @@ -20,7 +20,6 @@ /* Local headers */ #include "FileManager.h" -#include "ReplyManager.h" #include "ServerManager.h" /* Amount of data to be read/written at a time when transferring a piece */ Modified: hub/ServerManager.c =================================================================== --- hub/ServerManager.c 2005-01-15 02:40:59 UTC (rev 211) +++ hub/ServerManager.c 2005-01-15 02:53:17 UTC (rev 212) @@ -23,9 +23,9 @@ /* Local headers */ #include "FileManager.h" -#include "ReplyManager.h" #include "Server.h" #include "ServerManager.h" +#include "TransactionManager.h" static Collection server_table = 0; static Collection address_table = 0; @@ -133,7 +133,7 @@ } sock = server_sock(server); - monitor = replymgr_create_monitor(sock, txn); + monitor = txnmgr_create_monitor(sock, txn); lock_reader_release(server_table_lock); Added: hub/TransactionManager.c =================================================================== --- hub/TransactionManager.c 2005-01-15 02:40:59 UTC (rev 211) +++ hub/TransactionManager.c 2005-01-15 02:53:17 UTC (rev 212) @@ -0,0 +1,195 @@ +/** + @file TransactionManager.c + @brief Manages synchronous transactions sent to servers from hubs + */ +/* + Copyright (C)2005 Anthony Arcieri + All rights reserved. + + For licensing information, please see the file LICENSE + */ + +#include <machdep.h> + +#include <assert.h> + +/* Common headers */ +#include <Collection.h> +#include <Indexer.h> +#include <Transaction.h> +#include <debug.h> +#include <log.h> +#include <threadops.h> +#include <xmalloc.h> + +/* Local headers */ +#include "Server.h" +#include "TransactionManager.h" + +typedef struct _SvrTxnManager { + Indexer serial_pool; + Collection monitor_pool; +} *SvrTxnManager; + +struct _ReplyMonitor { + Mutex mutex; + Cond cond; + + TransactionIn txn; +}; + +static Collection txnmgr_pool = 0; +static Mutex txnmgr_pool_lock = 0; + +#define INITIALIZED (txnmgr_pool && txnmgr_pool_lock) + +#define MIN_SERIAL 1 +#define MAX_SERIAL 0xFFFFFFFF + +static ReplyMonitor replymonitor_create(void) +{ + ReplyMonitor monitor = NEW(ReplyMonitor); + + monitor->mutex = thr_mutex_create(); + monitor->cond = thr_cond_create(); + + return monitor; +} + +static void replymonitor_destroy(ReplyMonitor monitor) +{ + thr_mutex_destroy(monitor->mutex); + thr_cond_destroy(monitor->cond); + + xfree(monitor); +} + +static SvrTxnManager svrtxnmgr_create(void) +{ + SvrTxnManager mgr = NEW(SvrTxnManager); + + mgr->serial_pool = indexer_create(MIN_SERIAL, MAX_SERIAL); + mgr->monitor_pool = collection_create(); + + return mgr; +} + +static void svrtxnmgr_destroy(SvrTxnManager mgr) +{ + indexer_destroy(mgr->serial_pool); + collection_destroy(mgr->monitor_pool, (void (*)(void *))replymonitor_destroy); + + xfree(mgr); +} + +void txnmgr_init(void) +{ + assert(!INITIALIZED); + + txnmgr_pool = collection_create(); + txnmgr_pool_lock = thr_mutex_create(); +} + +void txnmgr_reinit(void) +{ + assert(INITIALIZED); +} + +void txnmgr_destroy(void) +{ + assert(INITIALIZED); + + collection_destroy(txnmgr_pool, (void (*)(void *))svrtxnmgr_destroy); + thr_mutex_destroy(txnmgr_pool_lock); +} + +/* Create a monitor for a reply to the given transaction. Sets a serial */ +ReplyMonitor txnmgr_create_monitor(int serverid, TransactionOut txn) +{ + SvrTxnManager mgr; + ReplyMonitor monitor; + uint32_t serial; + +#ifndef NDEBUG + debug("Reply monitor requested"); +#endif + + thr_mutex_lock(txnmgr_pool_lock); + + if(!(mgr = collection_lookup(txnmgr_pool, serverid))) + collection_insert(txnmgr_pool, serverid, mgr = svrtxnmgr_create()); + + /* Get a unique serial for the transaction */ + if(indexer_get(mgr->serial_pool, &serial) < 0) { + log_printf("!!! Warning: Couldn't send transaction due to serial pool exhaustion"); + thr_mutex_unlock(txnmgr_pool_lock); + + return 0; + } + + transaction_set_serial(txn, serial); + + /* Create a monitor object and register it for the given serial */ + monitor = replymonitor_create(); + collection_insert(mgr->monitor_pool, serial, monitor); + + thr_mutex_unlock(txnmgr_pool_lock); + +#ifndef NDEBUG + debug("Reply monitor generated"); +#endif + + return monitor; +} + +/* Wait for a transaction on a monitor. The monitor is destroyed when + the transaction is received. Returns NULL if connection is lost */ +TransactionIn replymonitor_wait(ReplyMonitor monitor) +{ + TransactionIn txn; + + thr_mutex_lock(monitor->mutex); + thr_cond_wait(monitor->cond, monitor->mutex); + + txn = monitor->txn; + thr_mutex_unlock(monitor->mutex); + + replymonitor_destroy(monitor); + + return txn; +} + +/* Attempt to dispatch a transaction reply. Returns 0 if it matched + an active monitor or -1 if it did not */ +int txnmgr_dispatch(int serverid, TransactionIn txn) +{ + SvrTxnManager mgr; + ReplyMonitor monitor; + + thr_mutex_lock(txnmgr_pool_lock); + + /* Lookup transaction manager for the specified server */ + if(!(mgr = collection_lookup(txnmgr_pool, serverid))) + goto err; + + /* Remove the monitor for the given serial */ + if(!(monitor = collection_remove(mgr->monitor_pool, transaction_serial(txn)))) + goto err; + + indexer_return(mgr->serial_pool, transaction_serial(txn)); + + thr_mutex_unlock(txnmgr_pool_lock); + + /* Send the transaction to the given monitor */ + thr_mutex_lock(monitor->mutex); + monitor->txn = txn; + thr_cond_signal(monitor->cond); + thr_mutex_unlock(monitor->mutex); + + return 0; +err: + thr_mutex_unlock(txnmgr_pool_lock); + log_printf("!!! Warning: Server protocol violation by server %d", serverid); + + return -1; +} Added: hub/TransactionManager.h =================================================================== --- hub/TransactionManager.h 2005-01-15 02:40:59 UTC (rev 211) +++ hub/TransactionManager.h 2005-01-15 02:53:17 UTC (rev 212) @@ -0,0 +1,29 @@ +#ifndef TRANSACTIONMANAGER_H +#define TRANSACTIONMANAGER_H + +#include <machdep.h> + +/* Common headers */ +#include <Transaction.h> + +/* Local headers */ +#include "Server.h" + +typedef struct _ReplyMonitor *ReplyMonitor; + +void txnmgr_init(void); +void txnmgr_reinit(void); +void txnmgr_destroy(void); + +/* Create a monitor for a reply to the given transaction. Sets a serial */ +ReplyMonitor txnmgr_create_monitor(int serverid, TransactionOut txn); + +/* Wait for a transaction on a monitor. The monitor is destroyed when + the transaction is received. Returns NULL if connection is lost */ +TransactionIn replymonitor_wait(ReplyMonitor monitor); + +/* Attempt to dispatch a transaction reply. Returns 0 if it matched + an active monitor or -1 if it did not */ +int txnmgr_dispatch(int serverid, TransactionIn txn); + +#endif Modified: hub/main.c =================================================================== --- hub/main.c 2005-01-15 02:40:59 UTC (rev 211) +++ hub/main.c 2005-01-15 02:53:17 UTC (rev 212) @@ -33,8 +33,8 @@ #include "FileHasher.h" #include "FileManager.h" #include "PieceServer.h" -#include "ReplyManager.h" #include "ServerManager.h" +#include "TransactionManager.h" #include "VFSMonitor.h" #include "config_keys.h" #include "netevent.h" @@ -74,7 +74,7 @@ { Component Logging; Component PoolCleaner; - Component ReplyManager; + Component TransactionManager; Component ServerManager; Component TransactionHandler; Component FileHasher; @@ -109,14 +109,14 @@ PoolCleaner = component_create(poolcleaner_init, 0, poolcleaner_destroy); - ReplyManager = component_create(replymgr_init, replymgr_reinit, replymgr_destroy); + TransactionManager = component_create(txnmgr_init, txnmgr_reinit, txnmgr_destroy); ServerManager = component_create(servermgr_init, servermgr_reinit, servermgr_destroy); - component_register_dependency(ServerManager, ReplyManager); + component_register_dependency(ServerManager, TransactionManager); TransactionHandler = component_create(servertxn_init, 0, servertxn_destroy); component_register_dependency(TransactionHandler, ServerManager); - component_register_dependency(TransactionHandler, ReplyManager); + component_register_dependency(TransactionHandler, TransactionManager); FileHasher = component_create(filehasher_init, 0, filehasher_destroy); component_register_dependency(FileHasher, Configuration); @@ -149,7 +149,7 @@ PieceServer = component_create(piecesvr_init, 0, piecesvr_destroy); component_register_dependency(PieceServer, Configuration); component_register_dependency(PieceServer, TransactionHandler); - component_register_dependency(PieceServer, ReplyManager); + component_register_dependency(PieceServer, TransactionManager); Listener = component_create(0, 0, listener_destroy); component_register_dependency(Listener, Configuration); Modified: hub/servertxn.c =================================================================== --- hub/servertxn.c 2005-01-15 02:40:59 UTC (rev 211) +++ hub/servertxn.c 2005-01-15 02:53:17 UTC (rev 212) @@ -24,7 +24,7 @@ /* Local headers */ #include "DirList.h" #include "FileManager.h" -#include "ReplyManager.h" +#include "TransactionManager.h" #include "VFSMonitor.h" #include "servertxn.h" @@ -66,7 +66,7 @@ /* Dispatch replies to the Reply Manager */ if(transaction_type(txn) == TXN_REPLY) { - if(replymgr_dispatch(sock, txn) < 0) + if(txnmgr_dispatch(sock, txn) < 0) transaction_in_destroy(txn); return 0; |
From: <tar...@pd...> - 2005-01-15 02:39:37
|
Author: tarcieri Date: 2005-01-14 19:40:59 -0700 (Fri, 14 Jan 2005) New Revision: 211 Added: common/replies.c common/replies.h Removed: common/transaction_replies.c common/transaction_replies.h Modified: common/Hasher.c common/Makefile.in common/log.c hub/FileHashes.c hub/Makefile.in hub/PieceServer.c hub/Server.c hub/Server.h hub/ServerManager.c hub/ServerManager.h hub/VFSMonitor.c hub/main.c hub/servertxn.c Log: Support of synchronous requests from hubs to servers and initial hub->server authorization Modified: common/Hasher.c =================================================================== --- common/Hasher.c 2005-01-15 02:40:50 UTC (rev 210) +++ common/Hasher.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Abstract hash cipher interface */ /* - Copyright (C)2004 Anthony Arcieri + Copyright (C)2004-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: common/Makefile.in =================================================================== --- common/Makefile.in 2005-01-15 02:40:50 UTC (rev 210) +++ common/Makefile.in 2005-01-15 02:40:59 UTC (rev 211) @@ -28,9 +28,9 @@ debug.o \ fileops.o \ log.o \ + replies.o \ socketops.o \ threadops.o \ - transaction_replies.o \ util.o \ xmalloc.o Modified: common/log.c =================================================================== --- common/log.c 2005-01-15 02:40:50 UTC (rev 210) +++ common/log.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Logging functions */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Copied: common/replies.c (from rev 209, common/transaction_replies.c) =================================================================== --- common/transaction_replies.c 2005-01-12 00:18:35 UTC (rev 209) +++ common/replies.c 2005-01-15 02:40:59 UTC (rev 211) @@ -0,0 +1,51 @@ +/** + @file replies.c +*/ +/* + Copyright (C)2001-05 Anthony Arcieri + All rights reserved. + + For licensing information, please see the file LICENSE +*/ + +#include <stdarg.h> + +#include "Transaction.h" +#include "txid.h" +#include "debug.h" +#include "replies.h" +#include "xmalloc.h" + +void reply_success(int sock, TransactionIn txn) +{ + TransactionOut reply; + + reply = transaction_create(TXN_REPLY, transaction_id(txn), 0); + transaction_set_serial(reply, transaction_serial(txn)); + transaction_write(sock, reply); + transaction_out_destroy(reply); +} + +void reply_error(int sock, uint32_t serial, const char *format, ...) +{ + va_list ap; + char *replystr; + TransactionOut reply; + + reply = transaction_create(TXN_REPLY, TXN_ERROR, 1); + transaction_set_serial(reply, serial); + + va_start(ap, format); + replystr = xvasprintf(format, ap); + va_end(ap); + +#ifndef NDEBUG + debug("Responding with error: %s", replystr); +#endif + + transaction_add_string(reply, OBJ_ERRMSG, replystr); + free(replystr); + + transaction_write(sock, reply); + transaction_out_destroy(reply); +} Copied: common/replies.h (from rev 209, common/transaction_replies.h) =================================================================== --- common/transaction_replies.h 2005-01-12 00:18:35 UTC (rev 209) +++ common/replies.h 2005-01-15 02:40:59 UTC (rev 211) @@ -0,0 +1,20 @@ +#ifndef TRANSACTION_REPLIES_H +#define TRANSACTION_REPLIES_H + +#include <machdep.h> + +/** + * @file replies.h + */ + +/** + * @defgroup replies Transaction Replies + * @{ + */ +#include "Transaction.h" + +void reply_success(int sock, TransactionIn txn); +void reply_error(int sock, uint32_t serial, const char *format, ...); + +/** @} */ +#endif Deleted: common/transaction_replies.c =================================================================== --- common/transaction_replies.c 2005-01-15 02:40:50 UTC (rev 210) +++ common/transaction_replies.c 2005-01-15 02:40:59 UTC (rev 211) @@ -1,50 +0,0 @@ -/** - @file transaction_replies.c -*/ -/* - Copyright (C)2001-04 Anthony Arcieri - All rights reserved. - - For licensing information, please see the file LICENSE -*/ - -#include <stdarg.h> - -#include "Transaction.h" -#include "txid.h" -#include "debug.h" -#include "xmalloc.h" - -void reply_success(int sock, TransactionIn txn) -{ - TransactionOut reply; - - reply = transaction_create(TXN_REPLY, transaction_id(txn), 0); - transaction_set_serial(reply, transaction_serial(txn)); - transaction_write(sock, reply); - transaction_out_destroy(reply); -} - -void reply_error(int sock, uint32_t serial, const char *format, ...) -{ - va_list ap; - char *replystr; - TransactionOut reply; - - reply = transaction_create(TXN_REPLY, TXN_ERROR, 1); - transaction_set_serial(reply, serial); - - va_start(ap, format); - replystr = xvasprintf(format, ap); - va_end(ap); - -#ifndef NDEBUG - debug("Responding with error: %s", replystr); -#endif - - transaction_add_string(reply, OBJ_ERRMSG, replystr); - free(replystr); - - transaction_write(sock, reply); - transaction_out_destroy(reply); -} Deleted: common/transaction_replies.h =================================================================== --- common/transaction_replies.h 2005-01-15 02:40:50 UTC (rev 210) +++ common/transaction_replies.h 2005-01-15 02:40:59 UTC (rev 211) @@ -1,20 +0,0 @@ -#ifndef TRANSACTION_REPLIES_H -#define TRANSACTION_REPLIES_H - -#include <machdep.h> - -/** - * @file transaction_replies.h - */ - -/** - * @defgroup transactionreplies Transaction Replies - * @{ - */ -#include "Transaction.h" - -void reply_success(int sock, TransactionIn txn); -void reply_error(int sock, uint32_t serial, const char *format, ...); - -/** @} */ -#endif Modified: hub/FileHashes.c =================================================================== --- hub/FileHashes.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/FileHashes.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Generates list of MD5/SHA1 for pieces within a file */ /* - Copyright (C)2004 Anthony Arcieri + Copyright (C)2004-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: hub/Makefile.in =================================================================== --- hub/Makefile.in 2005-01-15 02:40:50 UTC (rev 210) +++ hub/Makefile.in 2005-01-15 02:40:59 UTC (rev 211) @@ -9,6 +9,7 @@ FileHashes.o \ FileManager.o \ PieceServer.o \ + ReplyManager.o \ Server.o \ ServerManager.o \ VFSMonitor.o \ Modified: hub/PieceServer.c =================================================================== --- hub/PieceServer.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/PieceServer.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Provides piece service to clients and piece proxies */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -12,12 +12,16 @@ #include <machdep.h> /* Common headers */ +#include <Transaction.h> #include <debug.h> #include <fileops.h> #include <socketops.h> +#include <txid.h> /* Local headers */ #include "FileManager.h" +#include "ReplyManager.h" +#include "ServerManager.h" /* Amount of data to be read/written at a time when transferring a piece */ #define TRANSFER_CHUNK_SIZE 4096 @@ -32,8 +36,51 @@ { } +static int authorize_download(Sock client_sock, uint32_t client_addr, uint32_t server_addr, uint32_t file_handle, uint32_t piece) +{ + uint16_t replyid; + TransactionOut request; + TransactionIn reply; + +#ifndef NDEBUG + debug("Authorizing download with server"); +#endif + + request = transaction_create(TXN_COMMAND, TXN_AUTHDL, 3); + transaction_add_int32(request, OBJ_HANDLE, file_handle); + transaction_add_int32(request, OBJ_PIECEID, piece); + transaction_add_int32(request, OBJ_IPV4ADDR, client_addr); + + reply = servermgr_transact_by_ipv4_addr(server_addr, request); + transaction_out_destroy(request); + + if(!reply) { +#ifndef NDEBUG + debug("Server failed to respond"); +#endif + return -1; + } + + replyid = transaction_id(reply); + transaction_in_destroy(reply); + + if(!replyid) { +#ifndef NDEBUG + debug("Download unauthorized!"); +#endif + return -1; + } + +#ifndef NDEBUG + debug("Download authorized!"); +#endif + + return 0; +} + void piecesvr_download(Sock sock, uint32_t client_addr, uint32_t server_addr, uint16_t server_port, uint32_t file_handle, uint32_t piece) { + FileEntry entry; FileHashes hashes; FileHandle file; @@ -44,6 +91,9 @@ debug("Client at %08lx from %08lx:%d requested file %d", client_addr, server_addr, server_port, file_handle); #endif + if(authorize_download(sock, client_addr, server_addr, file_handle, piece) < 0) + return; + if(readsock_int32(sock, &offset) < 0) return; Modified: hub/Server.c =================================================================== --- hub/Server.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/Server.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Structure for storing server data */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -12,6 +12,7 @@ #include <machdep.h> /* Common headers */ +#include <Transaction.h> #include <socketops.h> #include <xmalloc.h> Modified: hub/Server.h =================================================================== --- hub/Server.h 2005-01-15 02:40:50 UTC (rev 210) +++ hub/Server.h 2005-01-15 02:40:59 UTC (rev 211) @@ -2,6 +2,9 @@ #define SERVER_H #include <machdep.h> + +#include <Transaction.h> + /** * @file Server.h * @brief Structure for storing server data @@ -11,7 +14,7 @@ Server server_create(int sock, uint32_t addr); void server_destroy(Server); -int server_sock(Server server); -uint32_t server_addr(Server server); +int server_sock(Server); +uint32_t server_addr(Server); #endif /* SERVER_H */ Modified: hub/ServerManager.c =================================================================== --- hub/ServerManager.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/ServerManager.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Stores information about all connected servers and proxies */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -23,13 +23,15 @@ /* Local headers */ #include "FileManager.h" +#include "ReplyManager.h" #include "Server.h" #include "ServerManager.h" static Collection server_table = 0; +static Collection address_table = 0; static Lock server_table_lock = 0; -#define INITIALIZED (server_table && server_table_lock) +#define INITIALIZED (server_table && address_table && server_table_lock) void servermgr_init() { @@ -37,6 +39,7 @@ server_table_lock = lock_create(LOCK_SHARED); server_table = collection_create(); + address_table = collection_create(); } void servermgr_reinit() @@ -53,6 +56,9 @@ collection_destroy(server_table, (void (*)(void *))server_destroy); server_table = 0; + + collection_destroy(address_table, 0); + address_table = 0; } int servermgr_add_ipv4_connection(int sock, uint32_t addr) @@ -69,6 +75,7 @@ lock_writer_acquire(server_table_lock); collection_insert(server_table, sock, server); + collection_insert(address_table, addr, server); lock_writer_release(server_table_lock); filemgr_blast_handles(sock); @@ -84,12 +91,10 @@ assert(INITIALIZED); lock_writer_acquire(server_table_lock); - server = (Server)collection_remove(server_table, sock); + assert((server = (Server)collection_remove(server_table, sock))); + collection_remove(address_table, server_addr(server)); lock_writer_release(server_table_lock); - /* Check to see internal structures are consistent */ - assert(server != 0); - log_printf("--- Server %s disconnected", t = xinet_ntoa(server_addr(server))); xfree(t); @@ -111,3 +116,31 @@ collection_iterate(server_table, broadcast_iterator, txn); lock_reader_release(server_table_lock); } + +TransactionIn servermgr_transact_by_ipv4_addr(uint32_t addr, TransactionOut txn) +{ + int sock; + Server server; + ReplyMonitor monitor; + + assert(INITIALIZED); + + lock_reader_acquire(server_table_lock); + + if(!(server = collection_lookup(address_table, addr))) { + lock_reader_release(server_table_lock); + return 0; + } + + sock = server_sock(server); + monitor = replymgr_create_monitor(sock, txn); + + lock_reader_release(server_table_lock); + + if(!monitor) + return 0; + + transaction_write(sock, txn); + + return replymonitor_wait(monitor); +} Modified: hub/ServerManager.h =================================================================== --- hub/ServerManager.h 2005-01-15 02:40:50 UTC (rev 210) +++ hub/ServerManager.h 2005-01-15 02:40:59 UTC (rev 211) @@ -9,10 +9,16 @@ void servermgr_reinit(); void servermgr_destroy(); +/* Add a server by its IPv4 address */ int servermgr_add_ipv4_connection(int sock, uint32_t addr); + +/* Remove a server */ void servermgr_remove_connection(int sock); /* Send a transaction to all connected servers */ void servermgr_broadcast(TransactionOut); +/* Send a transaction to the server at the specified address */ +TransactionIn servermgr_transact_by_ipv4_addr(uint32_t addr, TransactionOut); + #endif /* SERVERMANAGER_H */ Modified: hub/VFSMonitor.c =================================================================== --- hub/VFSMonitor.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/VFSMonitor.c 2005-01-15 02:40:59 UTC (rev 211) @@ -20,7 +20,7 @@ this thread needs to be implemented. */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: hub/main.c =================================================================== --- hub/main.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/main.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Squall PDTP hub main program */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -32,6 +32,8 @@ /* Local headers */ #include "FileHasher.h" #include "FileManager.h" +#include "PieceServer.h" +#include "ReplyManager.h" #include "ServerManager.h" #include "VFSMonitor.h" #include "config_keys.h" @@ -72,15 +74,17 @@ { Component Logging; Component PoolCleaner; + Component ReplyManager; + Component ServerManager; Component TransactionHandler; Component FileHasher; Component FileManager; Component VFSMonitor; Component Dispatcher; - Component ServerManager; Component Configuration; Component RNG; Component Listener; + Component PieceServer; #ifdef WIN32 /* Win32-specific components */ @@ -105,10 +109,14 @@ PoolCleaner = component_create(poolcleaner_init, 0, poolcleaner_destroy); + ReplyManager = component_create(replymgr_init, replymgr_reinit, replymgr_destroy); + ServerManager = component_create(servermgr_init, servermgr_reinit, servermgr_destroy); - + component_register_dependency(ServerManager, ReplyManager); + TransactionHandler = component_create(servertxn_init, 0, servertxn_destroy); component_register_dependency(TransactionHandler, ServerManager); + component_register_dependency(TransactionHandler, ReplyManager); FileHasher = component_create(filehasher_init, 0, filehasher_destroy); component_register_dependency(FileHasher, Configuration); @@ -138,6 +146,11 @@ component_register_dependency(RNG, Configuration); #endif + PieceServer = component_create(piecesvr_init, 0, piecesvr_destroy); + component_register_dependency(PieceServer, Configuration); + component_register_dependency(PieceServer, TransactionHandler); + component_register_dependency(PieceServer, ReplyManager); + Listener = component_create(0, 0, listener_destroy); component_register_dependency(Listener, Configuration); Modified: hub/servertxn.c =================================================================== --- hub/servertxn.c 2005-01-15 02:40:50 UTC (rev 210) +++ hub/servertxn.c 2005-01-15 02:40:59 UTC (rev 211) @@ -3,7 +3,7 @@ @brief Squall Hub's handlers for server to hub transactions */ /* - Copyright (C)2004 Anthony Arcieri + Copyright (C)2004-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -16,7 +16,7 @@ #include <Lock.h> #include <Transaction.h> #include <debug.h> -#include <transaction_replies.h> +#include <replies.h> #include <txid.h> #include <util.h> #include <xmalloc.h> @@ -24,6 +24,7 @@ /* Local headers */ #include "DirList.h" #include "FileManager.h" +#include "ReplyManager.h" #include "VFSMonitor.h" #include "servertxn.h" @@ -63,6 +64,14 @@ int ret; int (*handler)(int, TransactionIn); + /* Dispatch replies to the Reply Manager */ + if(transaction_type(txn) == TXN_REPLY) { + if(replymgr_dispatch(sock, txn) < 0) + transaction_in_destroy(txn); + + return 0; + } + if(!(handler = (int (*)(int, TransactionIn))collection_lookup(transaction_table, (CollectionKey)transaction_id(txn)))) { reply_error(sock, transaction_serial(txn), "Invalid transaction type (0x%x)", transaction_id(txn)); return 0; |
From: <tar...@pd...> - 2005-01-15 02:39:29
|
Author: tarcieri Date: 2005-01-14 19:40:50 -0700 (Fri, 14 Jan 2005) New Revision: 210 Modified: server/Client.c server/ClientManager.c server/HubConnection.c server/PieceSet.c server/Transfer.c server/TransferManager.c server/TransferManager.h server/clienttxn.c server/hubtxn.c server/main.c server/netevent.c Log: Support of synchronous requests from hubs to servers and initial hub->server authorization Modified: server/Client.c =================================================================== --- server/Client.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/Client.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Structure for storing client metadata */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/ClientManager.c =================================================================== --- server/ClientManager.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/ClientManager.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Central structure for storing all client metadata */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/HubConnection.c =================================================================== --- server/HubConnection.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/HubConnection.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Code for connecting to and communicating with a hub */ /* - Copyright (C)2004 Anthony Arcieri + Copyright (C)2004-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/PieceSet.c =================================================================== --- server/PieceSet.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/PieceSet.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Bit vector piece set management. */ /* - Copyright (C)2003-04 Matthew Bishop, Anthony Arcieri + Copyright (C)2003-05 Matthew Bishop, Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/Transfer.c =================================================================== --- server/Transfer.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/Transfer.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Structure for storing transfer information */ /* - Copyright (C)2004 Anthony Arcieri + Copyright (C)2004-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/TransferManager.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief State machine for all file transfers */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -307,4 +307,17 @@ void xfermgr_report_failure(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer) { +#ifndef NDEBUG + debug("Received failure report from %d for %d:%d from %08lx", uid, file_handle, piece, peer); +#endif } + +int xfermgr_auth_hubdl(uint32_t file_handle, uint32_t piece, uint32_t peer) +{ +#ifndef NDEBUG + debug("Received request to authorize hub to send %d:%d to %08lx", file_handle, piece, peer); +#endif + + /* XXX We will check to see if this transaction is authorized here */ + return 0; +} Modified: server/TransferManager.h =================================================================== --- server/TransferManager.h 2005-01-12 00:18:35 UTC (rev 209) +++ server/TransferManager.h 2005-01-15 02:40:50 UTC (rev 210) @@ -27,4 +27,6 @@ void xfermgr_report_success(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer); void xfermgr_report_failure(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer); +int xfermgr_auth_hubdl(uint32_t file_handle, uint32_t piece, uint32_t peer); + #endif /* TRANSFERMANAGER_H */ Modified: server/clienttxn.c =================================================================== --- server/clienttxn.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/clienttxn.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Squall Server's handlers for client transactions */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -17,7 +17,7 @@ #include <Collection.h> #include <Transaction.h> #include <debug.h> -#include <transaction_replies.h> +#include <replies.h> #include <txid.h> #include <util.h> #include <xmalloc.h> Modified: server/hubtxn.c =================================================================== --- server/hubtxn.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/hubtxn.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Squall Server's handlers for hub to server transactions */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE @@ -15,6 +15,7 @@ #include <Collection.h> #include <Transaction.h> #include <debug.h> +#include <replies.h> #include <txid.h> #include <xmalloc.h> @@ -24,6 +25,7 @@ static int txn_addhandle(int sock, TransactionIn txn); static int txn_remhandle(int sock, TransactionIn txn); +static int txn_authdl(int sock, TransactionIn txn); struct th_list_element { uint16_t txn_id; @@ -33,6 +35,7 @@ static struct th_list_element transaction_list[] = { { TXN_ADDHANDLE, txn_addhandle }, { TXN_REMHANDLE, txn_remhandle }, + { TXN_AUTHDL, txn_authdl }, { 0, 0 } }; @@ -119,3 +122,47 @@ return 0; } + +static int txn_authdl(int sock, TransactionIn txn) +{ + int i; + uint32_t handle, piece, peer; + TransactionOut reply; + +#ifndef NDEBUG + debug("Got authdl"); +#endif + + if((i = transaction_object_index(txn, OBJ_HANDLE)) < 0) + goto err; + + if(transaction_object_uint32(txn, i, &handle) < 0) + goto err; + + if((i = transaction_object_index(txn, OBJ_PIECEID)) < 0) + goto err; + + if(transaction_object_uint32(txn, i, &piece) < 0) + goto err; + + if((i = transaction_object_index(txn, OBJ_IPV4ADDR)) < 0) + goto err; + + if(transaction_object_uint32(txn, i, &peer) < 0) + goto err; + + if(xfermgr_auth_hubdl(handle, piece, peer) < 0) + goto err; + + reply_success(sock, txn); + + return 0; + +err: + reply = transaction_create(TXN_REPLY, TXN_ERROR, 0); + transaction_set_serial(reply, transaction_serial(txn)); + transaction_write(sock, reply); + transaction_out_destroy(reply); + + return 0; +} Modified: server/main.c =================================================================== --- server/main.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/main.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Squall PDTP server main program */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE Modified: server/netevent.c =================================================================== --- server/netevent.c 2005-01-12 00:18:35 UTC (rev 209) +++ server/netevent.c 2005-01-15 02:40:50 UTC (rev 210) @@ -3,7 +3,7 @@ @brief Network event handlers (invoked by dispatcher) */ /* - Copyright (C)2003-04 Anthony Arcieri + Copyright (C)2003-05 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE |
From: <tar...@pd...> - 2005-01-12 00:17:15
|
Author: tarcieri Date: 2005-01-11 17:18:35 -0700 (Tue, 11 Jan 2005) New Revision: 209 Modified: hub/PieceServer.c Log: Fixes to piece length calculation logic Modified: hub/PieceServer.c =================================================================== --- hub/PieceServer.c 2005-01-11 23:43:04 UTC (rev 208) +++ hub/PieceServer.c 2005-01-12 00:18:35 UTC (rev 209) @@ -83,8 +83,9 @@ debug("Total pieces in file: %d", filehashes_get_piece_count(hashes)); #endif - /* Recalculate length if last piece */ - if(piece == filehashes_get_piece_count(hashes) - 1) + /* If we're on the last piece and the piece length is not a multiple + of the file length, calculate the length of the last piece */ + if((piece == filehashes_get_piece_count(hashes) - 1) && (fileentry_get_length(entry) % piece_length > 0)) piece_length = fileentry_get_length(entry) % filehashes_get_piece_length(hashes); #ifndef NDEBUG |
From: <tar...@pd...> - 2005-01-11 23:41:42
|
Author: tarcieri Date: 2005-01-11 16:43:04 -0700 (Tue, 11 Jan 2005) New Revision: 208 Modified: server/TransferManager.c Log: Locking fixes to Transfer Manager Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2005-01-11 22:46:07 UTC (rev 207) +++ server/TransferManager.c 2005-01-11 23:43:04 UTC (rev 208) @@ -188,45 +188,31 @@ transaction_out_destroy(txn); } -struct piece_enqueue_args { - uint32_t addr; - uint32_t file_handle; - uint32_t piece; -}; - -static void piece_enqueue_callback(Client client, void *arg) +static void piece_enqueue(Client client, uint32_t file_handle, uint32_t piece) { - struct piece_enqueue_args *args = (struct piece_enqueue_args *)arg; - - client_piece_enqueue(client, args->addr, args->file_handle, args->piece); + /* XXX Temporary placeholder values */ + uint32_t addr = htonl(0x7F000001); + uint16_t port = 4044; + + client_piece_enqueue(client, addr, file_handle, piece); + peer_getpiece(client_sock(client), addr, port, file_handle, piece); } -static void piece_enqueue(int uid, uint32_t file_handle, uint32_t piece) +static void pick_next_piece_callback(Client client, void *arg) { - struct piece_enqueue_args args; - - /* XXX Super temporary placeholder */ - args.addr = htonl(0x7F000001); - args.file_handle = file_handle; - args.piece = piece; - - clientmgr_client_op(uid, LOCK_EXCL, piece_enqueue_callback, &args); - - peer_getpiece(uid, args.addr, 4044, file_handle, piece); -} - -static void pick_next_piece(int uid, uint32_t file_handle, PieceSet remaining_pieces) -{ - uint32_t piece; + uint32_t file_handle = *(uint32_t *)arg, piece; + PieceSet remaining_pieces; #ifndef NDEBUG - debug("Picking next piece for %d's transfer of %d", uid, file_handle); + debug("Picking next piece for %d's transfer of %d", client_sock(client), file_handle); #endif + remaining_pieces = client_get_remaining_pieces(client, file_handle); + if(!pieceset_count(remaining_pieces)) { /* XXX Transfer complete */ #ifndef NDEBUG - debug("%d:%d - Transfer complete!", uid, file_handle); + debug("%d:%d - Transfer complete!", client_sock(client), file_handle); #endif return; } @@ -234,9 +220,14 @@ /* XXX This logic will clearly be more complex in the future */ piece = pieceset_random_piece(remaining_pieces); - piece_enqueue(uid, file_handle, piece); + piece_enqueue(client, file_handle, piece); } +static void pick_next_piece(int uid, uint32_t file_handle) +{ + clientmgr_client_op(uid, LOCK_EXCL, pick_next_piece_callback, &file_handle); +} + struct addxfer_args { uint32_t file_handle; PieceSet remaining_pieces; @@ -247,7 +238,6 @@ struct addxfer_args *args = (struct addxfer_args *)arg; client_add_transfer(client, args->file_handle, args->remaining_pieces); - pick_next_piece(client_sock(client), args->file_handle, args->remaining_pieces); } void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) @@ -264,6 +254,7 @@ args.remaining_pieces = remaining_pieces; clientmgr_client_op(uid, LOCK_EXCL, xfermgr_add, &args); + pick_next_piece(uid, file_handle); } static void xfermgr_remove(Client client, void *arg) @@ -297,8 +288,6 @@ #endif pieceset_remove_piece(remaining_pieces, args->piece); - - pick_next_piece(client_sock(client), args->file_handle, remaining_pieces); } void xfermgr_report_success(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer) @@ -313,6 +302,7 @@ args.piece = piece; clientmgr_client_op(uid, LOCK_EXCL, add_completed_piece, &args); + pick_next_piece(uid, file_handle); } void xfermgr_report_failure(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer) |
From: <tar...@pd...> - 2005-01-11 22:44:48
|
Author: tarcieri Date: 2005-01-11 15:46:07 -0700 (Tue, 11 Jan 2005) New Revision: 207 Modified: common/log.c hub/VFSMonitor.c Log: Memory leak and deadlock fixes Modified: common/log.c =================================================================== --- common/log.c 2005-01-11 20:18:54 UTC (rev 206) +++ common/log.c 2005-01-11 22:46:07 UTC (rev 207) @@ -39,12 +39,7 @@ { va_list ap; struct systime st; - static Mutex log_mutex = 0; - if(!log_mutex) - log_mutex = thr_mutex_create(); - - thr_mutex_lock(log_mutex); get_systime(&st); fprintf(stderr, "[%02d:%02d:%02d] ", st.hour, st.minute, st.second); @@ -53,7 +48,6 @@ vfprintf(stderr, format, ap); va_end(ap); fputc('\n', stderr); - thr_mutex_unlock(log_mutex); } void log_error(const char *s) Modified: hub/VFSMonitor.c =================================================================== --- hub/VFSMonitor.c 2005-01-11 20:18:54 UTC (rev 206) +++ hub/VFSMonitor.c 2005-01-11 22:46:07 UTC (rev 207) @@ -888,7 +888,7 @@ assert(base_path); safecat(fullpath, PDTP_PATH_MAX, base_path, path, 0); - lock_reader_release(monitor_lock); + lock_reader_release(base_path_lock); /* Reverse slashes on Win32 */ #ifdef WIN32 |
From: <bi...@pd...> - 2005-01-11 20:17:35
|
Author: bishop Date: 2005-01-11 13:18:54 -0700 (Tue, 11 Jan 2005) New Revision: 206 Modified: server/PieceSet.c Log: Now we're xmalloc()ing the correct number of WORDS not bytes. *sigh* changed int -> unsigned for bit vector. Modified: server/PieceSet.c =================================================================== --- server/PieceSet.c 2005-01-10 21:53:27 UTC (rev 205) +++ server/PieceSet.c 2005-01-11 20:18:54 UTC (rev 206) @@ -24,11 +24,12 @@ #include "PieceSet.h" /** number of bits in a member of the PieceSet::ps_bits array */ -#define WORD_BITS (sizeof(int) * 8) -#define LAST_BIT (1 << (sizeof(int) - 1)) +#define WORD_BITS (sizeof(unsigned) * 8) +#define LAST_BIT (1 << (sizeof(unsigned) - 1)) +#define WORDSIZE (sizeof(unsigned)) struct _PieceSet { - int *ps_bits; + unsigned *ps_bits; int ps_numwords; int ps_numbits; }; @@ -60,13 +61,10 @@ set = (PieceSet)xmalloc(sizeof(struct _PieceSet)); set->ps_numbits = size; - set->ps_numwords = size / WORD_BITS + (size % WORD_BITS > 0 ? 1 : 0); + set->ps_bits = (unsigned *)xmalloc(WORDSIZE * set->ps_numwords); + memset(set->ps_bits, 0, WORDSIZE * set->ps_numwords); - set->ps_bits = (int *)xmalloc(set->ps_numwords); - - memset(set->ps_bits, 0, sizeof(int) * set->ps_numwords); - return set; } @@ -75,7 +73,7 @@ PieceSet set; set = (PieceSet)xmalloc(sizeof(struct _PieceSet)); - set->ps_bits = (int *)xmalloc(oldset->ps_numwords); + set->ps_bits = (unsigned *)xmalloc(WORDSIZE * oldset->ps_numwords); set->ps_numbits = oldset->ps_numbits; set->ps_numwords = oldset->ps_numwords; @@ -156,6 +154,8 @@ word = piece / WORD_BITS; bit = piece % WORD_BITS; + assert(word < set->ps_numwords); + set->ps_bits[word] &= ~(1 << bit); } @@ -178,7 +178,7 @@ { PieceSet result; int i, word, numwords; - int *resbits; + unsigned *resbits; #ifndef NDEBUG { @@ -195,7 +195,7 @@ numwords = sets[0]->ps_numwords; for(i = 0; i < numsets; i++) { - int *bits = sets[i]->ps_bits; + unsigned *bits = sets[i]->ps_bits; for(word = 0; word < numwords; word++) resbits[word] &= bits[word]; @@ -223,7 +223,7 @@ { PieceSet result; int i, word, numwords; - int *resbits; + unsigned *resbits; #ifndef NDEBUG { @@ -240,7 +240,7 @@ numwords = sets[0]->ps_numwords; for(i = 0; i < numsets; i++) { - int *bits = sets[i]->ps_bits; + unsigned *bits = sets[i]->ps_bits; for(word = 0; word < numwords; word++) resbits[word] |= bits[word]; @@ -305,9 +305,8 @@ { int word, bit, count, bits, n; - if(!(count = pieceset_count(set))) + if((count = pieceset_count(set)) == 0) return -1; - n = ps_random_number(count); assert(n <= count); |
From: <tar...@pd...> - 2005-01-10 21:52:12
|
Author: tarcieri Date: 2005-01-10 14:53:27 -0700 (Mon, 10 Jan 2005) New Revision: 205 Modified: configure Log: OpenSSL detection fixes Modified: configure =================================================================== --- configure 2005-01-06 00:26:26 UTC (rev 204) +++ configure 2005-01-10 21:53:27 UTC (rev 205) @@ -12,10 +12,9 @@ if [ "$OPENSSL_BASE" = "" ]; then printf "couldn't find OpenSSL!\n" - printf "Please make sure you have the OpenSSL libraries and head -ers installed" - printf "If you do, set the OPENSSL_BASE environment variable to - the correct base path" + printf "Please make sure you have the OpenSSL libraries and headers installed.\n" + printf "If you do, set the OPENSSL_BASE environment variable to the correct base path.\n" + exit 1 fi fi |
From: <tar...@pd...> - 2005-01-06 00:25:51
|
Author: tarcieri Date: 2005-01-05 17:26:26 -0700 (Wed, 05 Jan 2005) New Revision: 204 Modified: server/HubConnection.c Log: Fixes to hub connection shutdown code Modified: server/HubConnection.c =================================================================== --- server/HubConnection.c 2005-01-04 21:38:19 UTC (rev 203) +++ server/HubConnection.c 2005-01-06 00:26:26 UTC (rev 204) @@ -47,7 +47,8 @@ #define AUTH_HMAC_SHA1 0x0 static Sock hub_sock = -1; -static Lock hub_lock = 0; +static Mutex hub_mutex = 0; +static Cond hub_cond = 0; static unsigned serial_counter = 1; static Collection serial_collection = 0; @@ -323,18 +324,27 @@ log_printf("*** Connected successfully to hub server at %s:%d", hostname, port); xfree(hostname); - lock_writer_acquire(hub_lock); + thr_mutex_lock(hub_mutex); hub_sock = sock; - lock_writer_release(hub_lock); + thr_mutex_unlock(hub_mutex); hub_transaction_wait(); + thr_mutex_lock(hub_mutex); + + /* Check to see if we are terminating */ + if(hub_sock < 0) { + thr_cond_signal(hub_cond); + thr_mutex_unlock(hub_mutex); + + break; + } + log_printf("!!! Connection to hub lost!"); - lock_writer_acquire(hub_lock); socket_close(hub_sock); hub_sock = -1; - lock_writer_release(hub_lock); + thr_mutex_unlock(hub_mutex); } thr_exit(0); @@ -345,8 +355,11 @@ hub_transaction_router_init(); /* XXX Add rehashing support */ - if(!hub_lock) - hub_lock = lock_create(LOCK_SHARED); + if(!hub_mutex) + hub_mutex = thr_mutex_create(); + + if(!hub_cond) + hub_cond = thr_cond_create(); /* XXX Store the thread reference */ if(!thr_create(hubcxn_thread, 0)) @@ -357,26 +370,33 @@ { hub_transaction_router_destroy(); - /* XXX STUB! */ + /* XXX Unfinished */ + + thr_mutex_lock(hub_mutex); socket_close(hub_sock); hub_sock = -1; + thr_cond_wait(hub_cond, hub_mutex); + thr_mutex_unlock(hub_mutex); - lock_destroy(hub_lock); - hub_lock = 0; + thr_mutex_destroy(hub_mutex); + thr_cond_destroy(hub_cond); + + hub_mutex = 0; + hub_cond = 0; } /** Send a transaction which receives no reply */ int hubcxn_transact_async(TransactionOut txn) { - lock_reader_acquire(hub_lock); + thr_mutex_lock(hub_mutex); if(hub_sock == -1) { - lock_reader_release(hub_lock); + thr_mutex_lock(hub_mutex); return -1; } transaction_write(hub_sock, txn); - lock_reader_release(hub_lock); + thr_mutex_unlock(hub_mutex); return 0; } @@ -386,16 +406,16 @@ { MsgQueue queue; - lock_reader_acquire(hub_lock); + thr_mutex_lock(hub_mutex); if(hub_sock == -1) { - lock_reader_release(hub_lock); + thr_mutex_unlock(hub_mutex); return 0; } queue = hub_transaction_router_register(txn); transaction_write(hub_sock, txn); - lock_reader_release(hub_lock); + thr_mutex_unlock(hub_mutex); return hub_transaction_router_wait(queue); } |
From: <tar...@pd...> - 2005-01-04 21:37:46
|
Author: tarcieri Date: 2005-01-04 14:38:19 -0700 (Tue, 04 Jan 2005) New Revision: 203 Modified: server/PieceSet.c Log: Fixes to PieceSet RNG code Modified: server/PieceSet.c =================================================================== --- server/PieceSet.c 2005-01-04 05:21:47 UTC (rev 202) +++ server/PieceSet.c 2005-01-04 21:38:19 UTC (rev 203) @@ -23,10 +23,6 @@ /* Local headers */ #include "PieceSet.h" -/** The maximum number of pieces must be <= 2 ** RANDOM_BYTES */ -#define RANDOM_BYTES 2 -#define MAX_RANDOM_BYTES 0xffff - /** number of bits in a member of the PieceSet::ps_bits array */ #define WORD_BITS (sizeof(int) * 8) #define LAST_BIT (1 << (sizeof(int) - 1)) @@ -57,19 +53,6 @@ 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; -static unsigned ps_random_number(unsigned max) -{ - unsigned char buf[RANDOM_BYTES]; - unsigned r; - - rng_randbuf(buf, RANDOM_BYTES); - - r = buf[0]; - r |= (unsigned)buf[1] << 8; - - return r / (MAX_RANDOM_BYTES / max); -} - PieceSet pieceset_create(int size) { PieceSet set; @@ -308,6 +291,16 @@ } } +static unsigned ps_random_number(unsigned max) +{ + unsigned val; + + rng_randbuf(&val, sizeof(unsigned)); + + /* Since we're using an entropy-driven RNG this should be fine */ + return val % max; +} + int pieceset_random_piece(PieceSet set) { int word, bit, count, bits, n; @@ -316,6 +309,7 @@ return -1; n = ps_random_number(count); + assert(n <= count); count = 0; |
From: <tar...@pd...> - 2005-01-04 05:21:12
|
Author: tarcieri Date: 2005-01-03 22:21:47 -0700 (Mon, 03 Jan 2005) New Revision: 202 Modified: common/Hasher.c common/Hasher.h hub/FileHashes.c server/Client.c server/Client.h server/PieceSet.c server/TransferManager.c server/TransferManager.h server/clienttxn.c Log: Initial FTP-like file transfer support Modified: common/Hasher.c =================================================================== --- common/Hasher.c 2005-01-04 02:38:34 UTC (rev 201) +++ common/Hasher.c 2005-01-04 05:21:47 UTC (rev 202) @@ -53,6 +53,11 @@ (void (*)(void *, void *))sha1_get_digest } }; +unsigned hashalgorithm_digest_size(HashAlgorithm algorithm) +{ + return ciphers[algorithm].digest_size; +} + Hasher hasher_create(HashAlgorithm algorithm) { Hasher hasher = NEW(Hasher); Modified: common/Hasher.h =================================================================== --- common/Hasher.h 2005-01-04 02:38:34 UTC (rev 201) +++ common/Hasher.h 2005-01-04 05:21:47 UTC (rev 202) @@ -20,6 +20,13 @@ /** handle to the hasher */ typedef struct _Hasher *Hasher; +/** + * @brief return digest size of a given algorithm + * @param algorithm + * @returns length of digest + */ +unsigned hashalgorithm_digest_size(HashAlgorithm); + /** * @brief create a hasher * @param algorithm the algorithm to use Modified: hub/FileHashes.c =================================================================== --- hub/FileHashes.c 2005-01-04 02:38:34 UTC (rev 201) +++ hub/FileHashes.c 2005-01-04 05:21:47 UTC (rev 202) @@ -15,6 +15,7 @@ /* Common headers */ #include <Hasher.h> +#include <debug.h> #include <txid.h> #include <xmalloc.h> @@ -35,12 +36,8 @@ hashes->cipher = cipher; hashes->length = length; hashes->piece_length = piece_length; + hashes->piece_count = length / hashalgorithm_digest_size(cipher); - hashes->piece_count = (unsigned)(length / piece_length); - - if(length % piece_length) - hashes->piece_count++; - hashes->buffer = xmalloc(length); memcpy(hashes->buffer, hashlist, length); Modified: server/Client.c =================================================================== --- server/Client.c 2005-01-04 02:38:34 UTC (rev 201) +++ server/Client.c 2005-01-04 05:21:47 UTC (rev 202) @@ -39,6 +39,7 @@ client->addr = addr; client->lock = lock_create(LOCK_SHARED); + client->transfers = collection_create(); return client; } @@ -47,6 +48,7 @@ { socket_close(client->sock); + collection_destroy(client->transfers, 0); lock_destroy(client->lock); xfree(client); @@ -64,12 +66,19 @@ void client_add_transfer(Client client, uint32_t handle, PieceSet pieces) { + collection_insert(client->transfers, handle, pieces); } void client_remove_transfer(Client client, uint32_t handle) { + collection_remove(client->transfers, handle); } +PieceSet client_get_remaining_pieces(Client client, uint32_t handle) +{ + return (PieceSet)collection_lookup(client->transfers, handle); +} + void client_piece_enqueue(Client client, uint32_t addr, uint32_t file_handle, uint32_t piece) { #ifndef NDEBUG Modified: server/Client.h =================================================================== --- server/Client.h 2005-01-04 02:38:34 UTC (rev 201) +++ server/Client.h 2005-01-04 05:21:47 UTC (rev 202) @@ -22,6 +22,7 @@ void client_add_transfer(Client, uint32_t handle, PieceSet); void client_remove_transfer(Client, uint32_t handle); -void client_piece_enqueue(Client, uint32_t addr, uint32_t file, uint32_t piece); +PieceSet client_get_remaining_pieces(Client, uint32_t handle); +void client_piece_enqueue(Client client, uint32_t addr, uint32_t file_handle, uint32_t piece); #endif /* CLIENT_H */ Modified: server/PieceSet.c =================================================================== --- server/PieceSet.c 2005-01-04 02:38:34 UTC (rev 201) +++ server/PieceSet.c 2005-01-04 05:21:47 UTC (rev 202) @@ -312,9 +312,9 @@ { int word, bit, count, bits, n; - count = pieceset_count(set); - if(count == 0) + if(!(count = pieceset_count(set))) return -1; + n = ps_random_number(count); count = 0; Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2005-01-04 02:38:34 UTC (rev 201) +++ server/TransferManager.c 2005-01-04 05:21:47 UTC (rev 202) @@ -223,6 +223,14 @@ debug("Picking next piece for %d's transfer of %d", uid, file_handle); #endif + if(!pieceset_count(remaining_pieces)) { + /* XXX Transfer complete */ +#ifndef NDEBUG + debug("%d:%d - Transfer complete!", uid, file_handle); +#endif + return; + } + /* XXX This logic will clearly be more complex in the future */ piece = pieceset_random_piece(remaining_pieces); @@ -239,6 +247,7 @@ struct addxfer_args *args = (struct addxfer_args *)arg; client_add_transfer(client, args->file_handle, args->remaining_pieces); + pick_next_piece(client_sock(client), args->file_handle, args->remaining_pieces); } void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) @@ -255,8 +264,6 @@ args.remaining_pieces = remaining_pieces; clientmgr_client_op(uid, LOCK_EXCL, xfermgr_add, &args); - - pick_next_piece(uid, file_handle, remaining_pieces); } static void xfermgr_remove(Client client, void *arg) @@ -272,3 +279,42 @@ clientmgr_client_op(uid, LOCK_EXCL, xfermgr_remove, &file_handle); } + +struct addpiece_args { + uint32_t file_handle; + uint32_t piece; +}; + +static void add_completed_piece(Client client, void *arg) +{ + struct addpiece_args *args = (struct addpiece_args *)arg; + PieceSet remaining_pieces; + + remaining_pieces = client_get_remaining_pieces(client, args->file_handle); + +#ifndef NDEBUG + debug("Removing completed piece %d from set", args->piece); +#endif + + pieceset_remove_piece(remaining_pieces, args->piece); + + pick_next_piece(client_sock(client), args->file_handle, remaining_pieces); +} + +void xfermgr_report_success(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer) +{ + struct addpiece_args args; + +#ifndef NDEBUG + debug("Received success report from %d for %d:%d from %08lx", uid, file_handle, piece, peer); +#endif + + args.file_handle = file_handle; + args.piece = piece; + + clientmgr_client_op(uid, LOCK_EXCL, add_completed_piece, &args); +} + +void xfermgr_report_failure(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer) +{ +} Modified: server/TransferManager.h =================================================================== --- server/TransferManager.h 2005-01-04 02:38:34 UTC (rev 201) +++ server/TransferManager.h 2005-01-04 05:21:47 UTC (rev 202) @@ -24,4 +24,7 @@ void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces); void xfermgr_remove_transfer(int uid, uint32_t file_handle); +void xfermgr_report_success(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer); +void xfermgr_report_failure(int uid, uint32_t file_handle, uint32_t piece, uint32_t peer); + #endif /* TRANSFERMANAGER_H */ Modified: server/clienttxn.c =================================================================== --- server/clienttxn.c 2005-01-04 02:38:34 UTC (rev 201) +++ server/clienttxn.c 2005-01-04 05:21:47 UTC (rev 202) @@ -28,8 +28,10 @@ #include "TransferManager.h" #include "clienttxn.h" -static int txn_download(int sock, TransactionIn txn); -static int txn_fwdtohub(int sock, TransactionIn txn); +static int txn_download(int sock, TransactionIn); +static int txn_xfersuccess(int sock, TransactionIn); +static int txn_xferfail(int sock, TransactionIn); +static int txn_fwdtohub(int sock, TransactionIn); struct th_list_element { uint16_t txn_id; @@ -38,6 +40,8 @@ static struct th_list_element transaction_list[] = { { TXN_DOWNLOAD, txn_download }, + { TXN_XFERSUCCESS, txn_xfersuccess }, + { TXN_XFERFAIL, txn_xferfail }, { TXN_STATDIR, txn_fwdtohub }, { TXN_STATFILE, txn_fwdtohub }, { TXN_DIRLIST, txn_fwdtohub }, @@ -85,10 +89,10 @@ needed to remedy this problem */ static int txn_download(int sock, TransactionIn txn) { - int i, l; + int i; char *path; uint8_t *bptr; - uint32_t handle, piece_count = 0, range_low, range_high, lastval = 0, v32; + uint32_t handle, piece_count = 0, list_length, range_low, range_high, lastval = 0, v32; PieceSet set; TransactionOut reply; @@ -111,20 +115,29 @@ xfree(path); +#ifndef DEBUG + debug("%s has %d pieces", path, piece_count); +#endif + set = pieceset_create(piece_count); if((i = transaction_object_index(txn, OBJ_PIECELIST)) > 0) { - l = transaction_object_length(txn, i); - bptr = transaction_object_data(txn, i); + list_length = transaction_object_length(txn, i); - /* Validate length of piece list */ - if(piece_count * 8 != l) { + /* Check to see the length of the list is valid */ + if(list_length % 8) { pieceset_destroy(set); - reply_error(sock, transaction_serial(txn), "Invalid piece list length"); + reply_error(sock, transaction_serial(txn), "Malformed piece list"); return 0; } + + /* Recalculate the list from the number of bytes in the list to + the number of 2 * 32-bit elements */ + list_length /= 8; - for(i = 0; i < piece_count; i++) { + bptr = transaction_object_data(txn, i); + + for(i = 0; i < list_length; i++) { /* XXX Macro wrap - buffer overflow potential */ memcpy(&v32, bptr + i * 8, 4); range_low = ntohl(v32); @@ -133,17 +146,20 @@ range_high = ntohl(v32); /* Validate input values */ - if(range_high < range_low || (i && lastval >= range_low) || range_low > piece_count || range_high > piece_count) { + if(range_high < range_low || range_low > piece_count || range_high > piece_count || (i && lastval >= range_low)) { #ifndef DEBUG - debug("Invalid piece range: %d to %d in file of %d pieces", range_low, range_high, piece_count); + debug("Invalid piece range: %d to %d in list of %d pieces", range_low, range_high, piece_count); #endif pieceset_destroy(set); reply_error(sock, transaction_serial(txn), "Malformed piece list"); return 0; } - - pieceset_add_range(set, range_low, range_high); + +#ifndef NDEBUG + debug("Adding piece range: %d to %d", range_low, range_high); +#endif + pieceset_add_range(set, range_low, range_high - range_low + 1); lastval = range_high; } } @@ -158,8 +174,52 @@ xfermgr_add_transfer(sock, handle, set); return 0; -} +} +static int txn_xfersuccess(int sock, TransactionIn txn) +{ + int i; + uint32_t handle, piece, peer; + +#ifndef NDEBUG + debug("%d reports success!"); +#endif + + if((i = transaction_object_index(txn, OBJ_HANDLE)) < 0 || transaction_object_uint32(txn, i, &handle)) { +#ifndef NDEBUG + debug("Success report transaction had invalid handle"); +#endif + return 0; + } + + if((i = transaction_object_index(txn, OBJ_PIECEID)) < 0 || transaction_object_uint32(txn, i, &piece)) { +#ifndef NDEBUG + debug("Success report transaction had invalid piece ID"); +#endif + return 0; + } + + if((i = transaction_object_index(txn, OBJ_IPV4ADDR)) < 0 || transaction_object_uint32(txn, i, &peer)) { +#ifndef NDEBUG + debug("Success report transaction had invalid peer address"); +#endif + return 0; + } + + xfermgr_report_success(sock, handle, piece, peer); + + return 0; +} + +static int txn_xferfail(int sock, TransactionIn txn) +{ +#ifndef NDEBUG + debug("%d reports failure!"); +#endif + + return 0; +} + static int txn_fwdtohub(int sock, TransactionIn txnin) { uint32_t serial = transaction_serial(txnin); |
From: <bi...@pd...> - 2005-01-04 02:37:57
|
Author: bishop Date: 2005-01-03 19:38:34 -0700 (Mon, 03 Jan 2005) New Revision: 201 Modified: server/PieceSet.c server/PieceSet.h Log: Fixed pieceset_random_piece() to return -1 in the case of an empty PieceSet. Modified: server/PieceSet.c =================================================================== --- server/PieceSet.c 2005-01-04 02:09:01 UTC (rev 200) +++ server/PieceSet.c 2005-01-04 02:38:34 UTC (rev 201) @@ -312,7 +312,10 @@ { int word, bit, count, bits, n; - n = ps_random_number(pieceset_count(set)); + count = pieceset_count(set); + if(count == 0) + return -1; + n = ps_random_number(count); count = 0; Modified: server/PieceSet.h =================================================================== --- server/PieceSet.h 2005-01-04 02:09:01 UTC (rev 200) +++ server/PieceSet.h 2005-01-04 02:38:34 UTC (rev 201) @@ -41,6 +41,9 @@ /** Returns the set of all pieces not in the given set. */ PieceSet pieceset_not(PieceSet set); +/** Returns the total number of pieces in the set. */ +int pieceset_count(PieceSet set); + /** Returns a random piece in the set. */ int pieceset_random_piece(PieceSet set); |
From: <bi...@pd...> - 2005-01-04 02:08:24
|
Author: bishop Date: 2005-01-03 19:09:01 -0700 (Mon, 03 Jan 2005) New Revision: 200 Modified: configure Log: Quotes missing around OPENSSL_BASE in if statement. Modified: configure =================================================================== --- configure 2004-12-29 11:26:31 UTC (rev 199) +++ configure 2005-01-04 02:09:01 UTC (rev 200) @@ -10,7 +10,7 @@ if [ "$OPENSSL_BASE" = "" ]; then OPENSSL_BASE=`./find-openssl.sh` - if [ $OPENSSL_BASE = "" ]; then + if [ "$OPENSSL_BASE" = "" ]; then printf "couldn't find OpenSSL!\n" printf "Please make sure you have the OpenSSL libraries and head ers installed" |
From: <kur...@pd...> - 2004-12-29 11:25:54
|
Author: kuriyama Date: 2004-12-29 04:26:31 -0700 (Wed, 29 Dec 2004) New Revision: 199 Modified: hub/main.c server/main.c Log: Output process ID during startup. Modified: hub/main.c =================================================================== --- hub/main.c 2004-12-23 08:42:12 UTC (rev 198) +++ hub/main.c 2004-12-29 11:26:31 UTC (rev 199) @@ -188,6 +188,7 @@ log_printf("*** %s %s started on %04d-%02d-%02d", PACKAGE, VERSION, st.year, st.month, st.day); #ifndef WIN32 log_printf("*** Built for %s on %s", PLATFORM, BUILDDATE); + log_printf("*** Process ID is %d", getpid()); #endif /* WIN32 */ } Modified: server/main.c =================================================================== --- server/main.c 2004-12-23 08:42:12 UTC (rev 198) +++ server/main.c 2004-12-29 11:26:31 UTC (rev 199) @@ -181,6 +181,7 @@ log_printf("*** %s %s started on %04d-%02d-%02d", PACKAGE, VERSION, st.year, st.month, st.day); #ifndef WIN32 log_printf("*** Built for %s on %s", PLATFORM, BUILDDATE); + log_printf("*** Process ID is %d", getpid()); #endif /* WIN32 */ } |
From: <tar...@pd...> - 2004-12-23 08:41:31
|
Author: tarcieri Date: 2004-12-23 01:42:12 -0700 (Thu, 23 Dec 2004) New Revision: 198 Modified: server/clienttxn.c Log: Input validation updates Modified: server/clienttxn.c =================================================================== --- server/clienttxn.c 2004-12-23 08:26:43 UTC (rev 197) +++ server/clienttxn.c 2004-12-23 08:42:12 UTC (rev 198) @@ -125,14 +125,19 @@ } for(i = 0; i < piece_count; i++) { - /* AUDIT and macro wrap - buffer overflow potential */ + /* XXX Macro wrap - buffer overflow potential */ memcpy(&v32, bptr + i * 8, 4); range_low = ntohl(v32); memcpy(&v32, bptr + i * 8 + 4, 4); range_high = ntohl(v32); - if(range_high < range_low || (i && lastval >= range_low)) { + /* Validate input values */ + if(range_high < range_low || (i && lastval >= range_low) || range_low > piece_count || range_high > piece_count) { +#ifndef DEBUG + debug("Invalid piece range: %d to %d in file of %d pieces", range_low, range_high, piece_count); +#endif + pieceset_destroy(set); reply_error(sock, transaction_serial(txn), "Malformed piece list"); return 0; |
From: <tar...@pd...> - 2004-12-23 08:26:06
|
Author: tarcieri Date: 2004-12-23 01:26:43 -0700 (Thu, 23 Dec 2004) New Revision: 197 Modified: hub/PieceServer.c Log: Piece server improvements Modified: hub/PieceServer.c =================================================================== --- hub/PieceServer.c 2004-12-22 00:01:29 UTC (rev 196) +++ hub/PieceServer.c 2004-12-23 08:26:43 UTC (rev 197) @@ -19,6 +19,11 @@ /* Local headers */ #include "FileManager.h" +/* Amount of data to be read/written at a time when transferring a piece */ +#define TRANSFER_CHUNK_SIZE 4096 + +static void transfer_chunk(Sock sock, FileHandle file, uint64_t offset, uint32_t length); + void piecesvr_init() { } @@ -30,8 +35,10 @@ void piecesvr_download(Sock sock, uint32_t client_addr, uint32_t server_addr, uint16_t server_port, uint32_t file_handle, uint32_t piece) { FileEntry entry; + FileHashes hashes; FileHandle file; - uint32_t offset, length; + uint32_t offset, length, piece_length; + uint64_t file_offset; #ifndef NDEBUG debug("Client at %08lx from %08lx:%d requested file %d", client_addr, server_addr, server_port, file_handle); @@ -55,7 +62,45 @@ return; } + + hashes = fileentry_get_hashes(entry); + /* Validate piece index */ + if(piece >= filehashes_get_piece_count(hashes)) { +#ifndef NDEBUG + debug("Client requested invalid piece"); +#endif + + filemgr_return_entry(entry); + return; + } + + /* Calculate initial file offset */ + piece_length = filehashes_get_piece_length(hashes); + file_offset = (uint64_t)piece_length * piece; + +#ifndef NDEBUG + debug("Total pieces in file: %d", filehashes_get_piece_count(hashes)); +#endif + + /* Recalculate length if last piece */ + if(piece == filehashes_get_piece_count(hashes) - 1) + piece_length = fileentry_get_length(entry) % filehashes_get_piece_length(hashes); + +#ifndef NDEBUG + debug("piece length: %d requested chunk ends at: %d", piece_length, offset + length); +#endif + + /* Validate chunk request */ + if(offset + length > piece_length) { +#ifndef NDEBUG + debug("Client requested invalid chunk"); +#endif + + filemgr_return_entry(entry); + return; + } + file = fileentry_open(entry); filemgr_return_entry(entry); @@ -65,4 +110,41 @@ #endif return; } + + transfer_chunk(sock, file, file_offset + offset, length); + + file_close(file); } + +static void transfer_chunk(Sock sock, FileHandle file, uint64_t offset, uint32_t length) +{ + uint32_t count; + uint8_t buffer[TRANSFER_CHUNK_SIZE]; + + while(length) { + count = length > TRANSFER_CHUNK_SIZE ? TRANSFER_CHUNK_SIZE : length; + + if(file_read(file, buffer, count, offset) != count) { +#ifndef NDEBUG + debug("File read error"); +#endif + + return; + } + + if(writesock(sock, buffer, count) < 0) { +#ifndef NDEBUG + debug("Socket write error"); +#endif + + return; + } + +#ifndef NDEBUG + debug("Successfully wrote %d bytes", count); +#endif + + length -= count; + offset += count; + } +} |
From: <tar...@pd...> - 2004-12-22 00:00:51
|
Author: tarcieri Date: 2004-12-21 17:01:29 -0700 (Tue, 21 Dec 2004) New Revision: 196 Modified: hub/FileEntry.c hub/FileEntry.h hub/FileManager.c hub/PieceServer.c hub/PieceServer.h hub/netevent.c server/TransferManager.c Log: Download support improvements Modified: hub/FileEntry.c =================================================================== --- hub/FileEntry.c 2004-12-20 23:50:17 UTC (rev 195) +++ hub/FileEntry.c 2004-12-22 00:01:29 UTC (rev 196) @@ -13,6 +13,7 @@ /* Common headers */ #include <DirEntry.h> +#include <fileops.h> #include <xmalloc.h> /* Local headers */ @@ -109,3 +110,8 @@ file->hashes = filehashes_copy(hashes); } + +FileHandle fileentry_open(FileEntry file) +{ + return file_open(file->path); +} Modified: hub/FileEntry.h =================================================================== --- hub/FileEntry.h 2004-12-20 23:50:17 UTC (rev 195) +++ hub/FileEntry.h 2004-12-22 00:01:29 UTC (rev 196) @@ -8,6 +8,10 @@ #include <machdep.h> +/* Common headers */ +#include <fileops.h> + +/* Local headers */ #include "FileHashes.h" typedef struct _FileEntry *FileEntry; @@ -25,4 +29,7 @@ /* Set methods */ void fileentry_set_hashes(FileEntry, FileHashes); +/* Open the given entry for reading */ +FileHandle fileentry_open(FileEntry); + #endif /* FILEENTRY_H */ Modified: hub/FileManager.c =================================================================== --- hub/FileManager.c 2004-12-20 23:50:17 UTC (rev 195) +++ hub/FileManager.c 2004-12-22 00:01:29 UTC (rev 196) @@ -247,9 +247,21 @@ FileEntry filemgr_get_entry_by_handle(uint32_t handle, LockType type) { + FileEntry file, copy; + assert(INITIALIZED); - return 0; + lock_reader_acquire(handle_table_lock); + + if(!(file = collection_lookup(handle_table, handle))) { + lock_reader_release(handle_table_lock); + return 0; + } + + copy = fileentry_copy(file); + lock_reader_release(handle_table_lock); + + return copy; } void filemgr_return_entry(FileEntry entry) Modified: hub/PieceServer.c =================================================================== --- hub/PieceServer.c 2004-12-20 23:50:17 UTC (rev 195) +++ hub/PieceServer.c 2004-12-22 00:01:29 UTC (rev 196) @@ -1,16 +1,24 @@ /** @file PieceServer.c @brief Provides piece service to clients and piece proxies -*/ + */ /* Copyright (C)2003-04 Anthony Arcieri All rights reserved. For licensing information, please see the file LICENSE -*/ + */ #include <machdep.h> +/* Common headers */ +#include <debug.h> +#include <fileops.h> +#include <socketops.h> + +/* Local headers */ +#include "FileManager.h" + void piecesvr_init() { } @@ -18,3 +26,43 @@ void piecesvr_destroy() { } + +void piecesvr_download(Sock sock, uint32_t client_addr, uint32_t server_addr, uint16_t server_port, uint32_t file_handle, uint32_t piece) +{ + FileEntry entry; + FileHandle file; + uint32_t offset, length; + +#ifndef NDEBUG + debug("Client at %08lx from %08lx:%d requested file %d", client_addr, server_addr, server_port, file_handle); +#endif + + if(readsock_int32(sock, &offset) < 0) + return; + + if(readsock_int32(sock, &length) < 0) + return; + +#ifndef NDEBUG + debug("Requested piece %d, offset %d, length %d", piece, offset, length); +#endif + + if(!(entry = filemgr_get_entry_by_handle(file_handle, LOCK_SHARED))) { +#ifndef NDEBUG + debug("Client requested invalid file"); +#endif + + return; + + } + + file = fileentry_open(entry); + filemgr_return_entry(entry); + + if(!file) { +#ifndef NDEBUG + debug("Error opening requested file"); +#endif + return; + } +} Modified: hub/PieceServer.h =================================================================== --- hub/PieceServer.h 2004-12-20 23:50:17 UTC (rev 195) +++ hub/PieceServer.h 2004-12-22 00:01:29 UTC (rev 196) @@ -1,11 +1,19 @@ -#ifndef PIECESERVER_H -#define PIECESERVER_H - /** * @file PieceServer.h * @brief Provides piece service to clients and piece proxies */ + +#ifndef PIECESERVER_H +#define PIECESERVER_H + +#include <machdep.h> + +/* Common headers */ +#include <socketops.h> + void piecesvr_init(); void piecesvr_destroy(); - + +void piecesvr_download(Sock sock, uint32_t client_addr, uint32_t server_addr, uint16_t server_port, uint32_t file_handle, uint32_t piece); + #endif Modified: hub/netevent.c =================================================================== --- hub/netevent.c 2004-12-20 23:50:17 UTC (rev 195) +++ hub/netevent.c 2004-12-22 00:01:29 UTC (rev 196) @@ -19,10 +19,12 @@ #include <log.h> #include <msgval.h> #include <socketops.h> +#include <txid.h> #include <util.h> #include <xmalloc.h> /* Local headers */ +#include "PieceServer.h" #include "ServerManager.h" #include "netevent.h" #include "servertxn.h" @@ -90,14 +92,11 @@ return 0; } -static int piecesvr_connection_handler(int sock, uint32_t addr) +static int piecesvr_connection_handler(int sock, uint32_t client_addr) { - uint16_t value; + uint32_t server_addr, file_handle, piece; + uint16_t value, port; -#ifndef NDEBUG - debug("Received request for piece service"); -#endif - writesock_int32(sock, PTPP_MAGIC); /* Minimum protocol version supported, currently hardcoded to 1 */ @@ -118,12 +117,30 @@ if(readsock_int16(sock, &value) < 0) return -1; -#ifndef NDEBUG - debug("Client requested operation: %d\n", value); -#endif + /* Clients can only receive pieces from the hub */ + if(value != TXN_RECVPIECE) + return -1; - /* XXX Finish the transfer here */ - + /* Read server address for transfer */ + if(readsock_int32(sock, &server_addr) < 0) + return -1; + + /* Read server port */ + if(readsock_int16(sock, &port) < 0) + return -1; + + /* Read file handle ID */ + if(readsock_int32(sock, &file_handle) < 0) + return -1; + + /* Read piece ID */ + if(readsock_int32(sock, &piece) < 0) + return -1; + + /* Run the piece server for the current thread */ + piecesvr_download(sock, client_addr, server_addr, port, file_handle, piece); + + /* Once piece service is complete the client will always disconnect */ return -1; } @@ -144,8 +161,12 @@ xfree(t); /* Read the magic number from the client */ - if(readsock_int32(sock, &value) < 0) + if(readsock_int32(sock, &value) < 0) { +#ifndef NDEBUG + debug("Client disconnected before requesting a service"); +#endif goto err; + } switch(value) { case PDSP_MAGIC: @@ -159,6 +180,7 @@ break; default: + log_printf("*** Client sent bad service request header (%08x)", value); goto err; } Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-12-20 23:50:17 UTC (rev 195) +++ server/TransferManager.c 2004-12-22 00:01:29 UTC (rev 196) @@ -177,7 +177,7 @@ { TransactionOut txn; - txn = transaction_create(TXN_COMMAND, TXN_SENDPIECE, 4); + txn = transaction_create(TXN_COMMAND, TXN_RECVPIECE, 4); transaction_add_int32(txn, OBJ_HANDLE, file_handle); transaction_add_int32(txn, OBJ_PIECEID, piece); |
From: <tar...@pd...> - 2004-12-20 23:49:39
|
Author: tarcieri Date: 2004-12-20 16:50:17 -0700 (Mon, 20 Dec 2004) New Revision: 195 Modified: hub/netevent.c hub/netevent.h server/TransferManager.c Log: Bugfixes in transfer manager and addition of piece server handshaking code Modified: hub/netevent.c =================================================================== --- hub/netevent.c 2004-12-17 23:49:38 UTC (rev 194) +++ hub/netevent.c 2004-12-20 23:50:17 UTC (rev 195) @@ -29,10 +29,10 @@ /* Protocol magic numbers */ #define PDSP_MAGIC 0x50445350 -#define PTPP_MAGIC 0x50745050 +#define PTPP_MAGIC 0x50545050 /** Handle authorization. Zero on success, -1 on failure */ -static int source_auth_handler(int sock) +static int server_auth_handler(int sock) { int ret; char *key; @@ -54,12 +54,12 @@ return ret; } -static int source_connection_handler(int sock, uint32_t addr) +static int server_connection_handler(int sock, uint32_t addr) { char *t; uint16_t value; - if(source_auth_handler(sock) < 0) + if(server_auth_handler(sock) < 0) return -1; writesock_int32(sock, PDSP_MAGIC); @@ -82,7 +82,7 @@ servermgr_add_ipv4_connection(sock, addr); /* Add the server connection to the dispatcher */ - dispatcher_add(sock, source_transaction_handler); + dispatcher_add(sock, server_transaction_handler); log_printf("*** Successfully authenticated server connection from: %s", t = xinet_ntoa(addr)); xfree(t); @@ -92,6 +92,38 @@ static int piecesvr_connection_handler(int sock, uint32_t addr) { + uint16_t value; + +#ifndef NDEBUG + debug("Received request for piece service"); +#endif + + writesock_int32(sock, PTPP_MAGIC); + + /* Minimum protocol version supported, currently hardcoded to 1 */ + writesock_int16(sock, 1); + + /* Maximum protocol version supported, currently hardcoded to 1 */ + writesock_int16(sock, 1); + + /* Read the client's selected protocol version */ + if(readsock_int16(sock, &value) < 0) + return -1; + + /* Only valid selection at this point */ + if(value != 1) + return -1; + + /* Read the client's selected opcode */ + if(readsock_int16(sock, &value) < 0) + return -1; + +#ifndef NDEBUG + debug("Client requested operation: %d\n", value); +#endif + + /* XXX Finish the transfer here */ + return -1; } @@ -117,7 +149,7 @@ switch(value) { case PDSP_MAGIC: - if(source_connection_handler(sock, addr) < 0) + if(server_connection_handler(sock, addr) < 0) goto err; break; @@ -138,7 +170,7 @@ socket_close(sock); } -void source_transaction_handler(msgval *arg) +void server_transaction_handler(msgval *arg) { TransactionIn txn; int sock = arg->num; @@ -148,5 +180,5 @@ return; } - dispatcher_add(sock, source_transaction_handler); + dispatcher_add(sock, server_transaction_handler); } Modified: hub/netevent.h =================================================================== --- hub/netevent.h 2004-12-17 23:49:38 UTC (rev 194) +++ hub/netevent.h 2004-12-20 23:50:17 UTC (rev 195) @@ -11,7 +11,7 @@ /* Incoming connection handlers */ void incoming_connection_handler(msgval *arg); -/* Handler for source transactions */ -void source_transaction_handler(msgval *arg); +/* Handler for server transactions */ +void server_transaction_handler(msgval *arg); #endif /* PDTPSS_NETEVENT_H */ Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-12-17 23:49:38 UTC (rev 194) +++ server/TransferManager.c 2004-12-20 23:50:17 UTC (rev 195) @@ -212,7 +212,7 @@ clientmgr_client_op(uid, LOCK_EXCL, piece_enqueue_callback, &args); - peer_getpiece(uid, args.addr, 4045, file_handle, piece); + peer_getpiece(uid, args.addr, 4044, file_handle, piece); } static void pick_next_piece(int uid, uint32_t file_handle, PieceSet remaining_pieces) |
From: <tar...@pd...> - 2004-12-17 23:48:57
|
Author: tarcieri Date: 2004-12-17 16:49:38 -0700 (Fri, 17 Dec 2004) New Revision: 194 Modified: server/TransferManager.c server/clienttxn.c Log: Minor bugfixes in transfer manager Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-10-26 07:08:00 UTC (rev 193) +++ server/TransferManager.c 2004-12-17 23:49:38 UTC (rev 194) @@ -182,7 +182,7 @@ transaction_add_int32(txn, OBJ_HANDLE, file_handle); transaction_add_int32(txn, OBJ_PIECEID, piece); transaction_add_int32(txn, OBJ_IPV4ADDR, peeraddr); - transaction_add_int32(txn, OBJ_PORT, peerport); + transaction_add_int16(txn, OBJ_PORT, peerport); transaction_write(uid, txn); transaction_out_destroy(txn); Modified: server/clienttxn.c =================================================================== --- server/clienttxn.c 2004-10-26 07:08:00 UTC (rev 193) +++ server/clienttxn.c 2004-12-17 23:49:38 UTC (rev 194) @@ -143,14 +143,15 @@ } } + reply = transaction_create(TXN_REPLY, transaction_id(txn), 1); + transaction_set_serial(reply, transaction_serial(txn)); + transaction_add_int32(reply, OBJ_HANDLE, handle); + transaction_write(sock, reply); + transaction_out_destroy(reply); + + /* We may need to check for an error here */ xfermgr_add_transfer(sock, handle, set); - reply = transaction_create(TXN_REPLY, transaction_id(txn), 1); - transaction_set_serial(reply, transaction_serial(txn)); - transaction_add_int32(reply, OBJ_HANDLE, handle); - transaction_write(sock, reply); - transaction_out_destroy(reply); - return 0; } |
From: <tar...@pd...> - 2004-10-26 07:08:11
|
Author: tarcieri Date: 2004-10-26 01:08:00 -0600 (Tue, 26 Oct 2004) New Revision: 193 Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.html doc/draft-arcieri-peer-distributed-transfer-protocol.txt doc/draft-arcieri-peer-distributed-transfer-protocol.xml server/Client.c server/Client.h server/TransferManager.c server/netevent.c Log: TransferManager and protocol specification updates Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.html =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.html 2004-10-25 01:39:41 UTC (rev 192) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.html 2004-10-26 07:08:00 UTC (rev 193) @@ -87,7 +87,7 @@ <table summary="layout" width="66%" border="0" cellpadding="0" cellspacing="0"><tr><td><table summary="layout" width="100%" border="0" cellpadding="2" cellspacing="1"> <tr><td class="header">Network Working Group</td><td class="header">A. Arcieri, Ed.</td></tr> <tr><td class="header">Internet-Draft</td><td class="header">PDTP.org</td></tr> -<tr><td class="header">Expires: April 20, 2005</td><td class="header">October 20, 2004</td></tr> +<tr><td class="header">Expires: April 26, 2005</td><td class="header">October 26, 2004</td></tr> </table></td></tr></table> <div align="right"><span class="title"><br />Peer Distributed Transfer Protocol</span></div> <div align="right"><span class="title"><br />draft-arcieri-peer-distributed-transfer-protocol</span></div> @@ -113,7 +113,7 @@ The list of Internet-Draft Shadow Directories can be accessed at <a href='http://www.ietf.org/shadow.html'>http://www.ietf.org/shadow.html</a>.</p> <p> -This Internet-Draft will expire on April 20, 2005.</p> +This Internet-Draft will expire on April 26, 2005.</p> <h3>Copyright Notice</h3> <p> @@ -867,7 +867,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -889,7 +889,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -911,7 +911,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -951,7 +951,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -975,7 +975,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -994,7 +994,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -1016,7 +1016,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -1279,7 +1279,7 @@ Object ID: 0x2 (Path) [See Appendix A for format] Payload: string Path to file -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint16 Number of pieces in file </pre> Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.txt =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.txt 2004-10-25 01:39:41 UTC (rev 192) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.txt 2004-10-26 07:08:00 UTC (rev 193) @@ -2,7 +2,7 @@ Network Working Group A. Arcieri, Ed. Internet-Draft PDTP.org -Expires: April 20, 2005 October 20, 2004 +Expires: April 26, 2005 October 26, 2004 Peer Distributed Transfer Protocol @@ -28,7 +28,7 @@ The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. - This Internet-Draft will expire on April 20, 2005. + This Internet-Draft will expire on April 26, 2005. Copyright Notice @@ -52,7 +52,7 @@ -Arcieri Expires April 20, 2005 [Page 1] +Arcieri Expires April 26, 2005 [Page 1] Internet-Draft PDTP Protocol Specification October 2004 @@ -108,7 +108,7 @@ -Arcieri Expires April 20, 2005 [Page 2] +Arcieri Expires April 26, 2005 [Page 2] Internet-Draft PDTP Protocol Specification October 2004 @@ -164,7 +164,7 @@ -Arcieri Expires April 20, 2005 [Page 3] +Arcieri Expires April 26, 2005 [Page 3] Internet-Draft PDTP Protocol Specification October 2004 @@ -220,7 +220,7 @@ -Arcieri Expires April 20, 2005 [Page 4] +Arcieri Expires April 26, 2005 [Page 4] Internet-Draft PDTP Protocol Specification October 2004 @@ -276,7 +276,7 @@ -Arcieri Expires April 20, 2005 [Page 5] +Arcieri Expires April 26, 2005 [Page 5] Internet-Draft PDTP Protocol Specification October 2004 @@ -332,7 +332,7 @@ -Arcieri Expires April 20, 2005 [Page 6] +Arcieri Expires April 26, 2005 [Page 6] Internet-Draft PDTP Protocol Specification October 2004 @@ -388,7 +388,7 @@ -Arcieri Expires April 20, 2005 [Page 7] +Arcieri Expires April 26, 2005 [Page 7] Internet-Draft PDTP Protocol Specification October 2004 @@ -444,7 +444,7 @@ -Arcieri Expires April 20, 2005 [Page 8] +Arcieri Expires April 26, 2005 [Page 8] Internet-Draft PDTP Protocol Specification October 2004 @@ -500,7 +500,7 @@ -Arcieri Expires April 20, 2005 [Page 9] +Arcieri Expires April 26, 2005 [Page 9] Internet-Draft PDTP Protocol Specification October 2004 @@ -556,7 +556,7 @@ -Arcieri Expires April 20, 2005 [Page 10] +Arcieri Expires April 26, 2005 [Page 10] Internet-Draft PDTP Protocol Specification October 2004 @@ -612,7 +612,7 @@ -Arcieri Expires April 20, 2005 [Page 11] +Arcieri Expires April 26, 2005 [Page 11] Internet-Draft PDTP Protocol Specification October 2004 @@ -668,7 +668,7 @@ -Arcieri Expires April 20, 2005 [Page 12] +Arcieri Expires April 26, 2005 [Page 12] Internet-Draft PDTP Protocol Specification October 2004 @@ -724,7 +724,7 @@ -Arcieri Expires April 20, 2005 [Page 13] +Arcieri Expires April 26, 2005 [Page 13] Internet-Draft PDTP Protocol Specification October 2004 @@ -768,7 +768,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -780,7 +780,7 @@ -Arcieri Expires April 20, 2005 [Page 14] +Arcieri Expires April 26, 2005 [Page 14] Internet-Draft PDTP Protocol Specification October 2004 @@ -795,7 +795,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -814,7 +814,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -836,7 +836,7 @@ -Arcieri Expires April 20, 2005 [Page 15] +Arcieri Expires April 26, 2005 [Page 15] Internet-Draft PDTP Protocol Specification October 2004 @@ -861,7 +861,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -883,7 +883,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -892,7 +892,7 @@ -Arcieri Expires April 20, 2005 [Page 16] +Arcieri Expires April 26, 2005 [Page 16] Internet-Draft PDTP Protocol Specification October 2004 @@ -908,7 +908,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -927,7 +927,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -948,7 +948,7 @@ -Arcieri Expires April 20, 2005 [Page 17] +Arcieri Expires April 26, 2005 [Page 17] Internet-Draft PDTP Protocol Specification October 2004 @@ -1004,7 +1004,7 @@ -Arcieri Expires April 20, 2005 [Page 18] +Arcieri Expires April 26, 2005 [Page 18] Internet-Draft PDTP Protocol Specification October 2004 @@ -1060,7 +1060,7 @@ -Arcieri Expires April 20, 2005 [Page 19] +Arcieri Expires April 26, 2005 [Page 19] Internet-Draft PDTP Protocol Specification October 2004 @@ -1116,7 +1116,7 @@ -Arcieri Expires April 20, 2005 [Page 20] +Arcieri Expires April 26, 2005 [Page 20] Internet-Draft PDTP Protocol Specification October 2004 @@ -1172,7 +1172,7 @@ -Arcieri Expires April 20, 2005 [Page 21] +Arcieri Expires April 26, 2005 [Page 21] Internet-Draft PDTP Protocol Specification October 2004 @@ -1212,7 +1212,7 @@ Object ID: 0x2 (Path) [See Appendix A for format] Payload: string Path to file - Object ID: 0x6 (Piece ID) + Object ID: 0x5 (Piece ID) Payload: uint16 Number of pieces in file This transaction informs the server that the given handle is now @@ -1228,7 +1228,7 @@ -Arcieri Expires April 20, 2005 [Page 22] +Arcieri Expires April 26, 2005 [Page 22] Internet-Draft PDTP Protocol Specification October 2004 @@ -1284,7 +1284,7 @@ -Arcieri Expires April 20, 2005 [Page 23] +Arcieri Expires April 26, 2005 [Page 23] Internet-Draft PDTP Protocol Specification October 2004 @@ -1340,7 +1340,7 @@ -Arcieri Expires April 20, 2005 [Page 24] +Arcieri Expires April 26, 2005 [Page 24] Internet-Draft PDTP Protocol Specification October 2004 @@ -1396,7 +1396,7 @@ -Arcieri Expires April 20, 2005 [Page 25] +Arcieri Expires April 26, 2005 [Page 25] Internet-Draft PDTP Protocol Specification October 2004 @@ -1452,7 +1452,7 @@ -Arcieri Expires April 20, 2005 [Page 26] +Arcieri Expires April 26, 2005 [Page 26] Internet-Draft PDTP Protocol Specification October 2004 @@ -1508,7 +1508,7 @@ -Arcieri Expires April 20, 2005 [Page 27] +Arcieri Expires April 26, 2005 [Page 27] Internet-Draft PDTP Protocol Specification October 2004 @@ -1564,7 +1564,7 @@ -Arcieri Expires April 20, 2005 [Page 28] +Arcieri Expires April 26, 2005 [Page 28] Internet-Draft PDTP Protocol Specification October 2004 @@ -1620,7 +1620,7 @@ -Arcieri Expires April 20, 2005 [Page 29] +Arcieri Expires April 26, 2005 [Page 29] Internet-Draft PDTP Protocol Specification October 2004 @@ -1676,5 +1676,5 @@ -Arcieri Expires April 20, 2005 [Page 30] +Arcieri Expires April 26, 2005 [Page 30] Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.xml =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.xml 2004-10-25 01:39:41 UTC (rev 192) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.xml 2004-10-26 07:08:00 UTC (rev 193) @@ -6,7 +6,7 @@ <author initials="A." surname="Arcieri" fullname="Anthony Arcieri" role="editor"> <organization>PDTP.org</organization> </author> - <date day="20" month="October" year="2004" /> + <date day="26" month="October" year="2004" /> <area>Internet</area> <keyword>I-D</keyword> <keyword>Internet-Draft</keyword> @@ -707,7 +707,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -731,7 +731,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -755,7 +755,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -799,7 +799,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -825,7 +825,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -846,7 +846,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -870,7 +870,7 @@ Object ID: 0x1 (File Handle) Payload: uint32 File handle ID -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint32 Piece number Object ID: 0x10 (IPv4 Address) @@ -1130,7 +1130,7 @@ Object ID: 0x2 (Path) [See Appendix A for format] Payload: string Path to file -Object ID: 0x6 (Piece ID) +Object ID: 0x5 (Piece ID) Payload: uint16 Number of pieces in file </artwork> </figure> Modified: server/Client.c =================================================================== --- server/Client.c 2004-10-25 01:39:41 UTC (rev 192) +++ server/Client.c 2004-10-26 07:08:00 UTC (rev 193) @@ -14,7 +14,9 @@ /* Common headers */ #include <Collection.h> #include <Lock.h> +#include <debug.h> #include <socketops.h> +#include <util.h> #include <xmalloc.h> /* Local headers */ @@ -68,6 +70,16 @@ { } +void client_piece_enqueue(Client client, uint32_t addr, uint32_t file_handle, uint32_t piece) +{ +#ifndef NDEBUG + char *t; + + debug("Client %d: Enqueuing piece %d of file %d through host %s", client->sock, piece, file_handle, t = xinet_ntoa(addr)); + xfree(t); +#endif +} + /* Used exclusively by ClientManager */ Lock client_lock(Client client) { Modified: server/Client.h =================================================================== --- server/Client.h 2004-10-25 01:39:41 UTC (rev 192) +++ server/Client.h 2004-10-26 07:08:00 UTC (rev 193) @@ -19,7 +19,9 @@ int client_sock(Client); uint32_t client_addr(Client); -void client_add_transfer(Client client, uint32_t handle, PieceSet pieces); -void client_remove_transfer(Client client, uint32_t handle); +void client_add_transfer(Client, uint32_t handle, PieceSet); +void client_remove_transfer(Client, uint32_t handle); +void client_piece_enqueue(Client, uint32_t addr, uint32_t file, uint32_t piece); + #endif /* CLIENT_H */ Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-10-25 01:39:41 UTC (rev 192) +++ server/TransferManager.c 2004-10-26 07:08:00 UTC (rev 193) @@ -17,7 +17,9 @@ #include <Collection.h> #include <HashTable.h> #include <Lock.h> +#include <Transaction.h> #include <debug.h> +#include <txid.h> #include <xmalloc.h> /* Local headers */ @@ -171,6 +173,62 @@ return ret; } +static void peer_getpiece(int uid, uint32_t peeraddr, uint16_t peerport, uint32_t file_handle, uint32_t piece) +{ + TransactionOut txn; + + txn = transaction_create(TXN_COMMAND, TXN_SENDPIECE, 4); + + transaction_add_int32(txn, OBJ_HANDLE, file_handle); + transaction_add_int32(txn, OBJ_PIECEID, piece); + transaction_add_int32(txn, OBJ_IPV4ADDR, peeraddr); + transaction_add_int32(txn, OBJ_PORT, peerport); + + transaction_write(uid, txn); + transaction_out_destroy(txn); +} + +struct piece_enqueue_args { + uint32_t addr; + uint32_t file_handle; + uint32_t piece; +}; + +static void piece_enqueue_callback(Client client, void *arg) +{ + struct piece_enqueue_args *args = (struct piece_enqueue_args *)arg; + + client_piece_enqueue(client, args->addr, args->file_handle, args->piece); +} + +static void piece_enqueue(int uid, uint32_t file_handle, uint32_t piece) +{ + struct piece_enqueue_args args; + + /* XXX Super temporary placeholder */ + args.addr = htonl(0x7F000001); + args.file_handle = file_handle; + args.piece = piece; + + clientmgr_client_op(uid, LOCK_EXCL, piece_enqueue_callback, &args); + + peer_getpiece(uid, args.addr, 4045, file_handle, piece); +} + +static void pick_next_piece(int uid, uint32_t file_handle, PieceSet remaining_pieces) +{ + uint32_t piece; + +#ifndef NDEBUG + debug("Picking next piece for %d's transfer of %d", uid, file_handle); +#endif + + /* XXX This logic will clearly be more complex in the future */ + piece = pieceset_random_piece(remaining_pieces); + + piece_enqueue(uid, file_handle, piece); +} + struct addxfer_args { uint32_t file_handle; PieceSet remaining_pieces; @@ -197,6 +255,8 @@ args.remaining_pieces = remaining_pieces; clientmgr_client_op(uid, LOCK_EXCL, xfermgr_add, &args); + + pick_next_piece(uid, file_handle, remaining_pieces); } static void xfermgr_remove(Client client, void *arg) Modified: server/netevent.c =================================================================== --- server/netevent.c 2004-10-25 01:39:41 UTC (rev 192) +++ server/netevent.c 2004-10-26 07:08:00 UTC (rev 193) @@ -14,6 +14,7 @@ /* Common headers */ #include <Dispatcher.h> #include <Transaction.h> +#include <debug.h> #include <log.h> #include <msgval.h> #include <socketops.h> @@ -37,7 +38,7 @@ static int pdtp_connection_handler(int sock, uint32_t addr) { uint16_t value; - uint8_t vhost[MAX_VHOST_LENGTH]; + uint8_t vhost[MAX_VHOST_LENGTH] = { 0 }; /* XXX Peer redirection support goes here */ writesock_int32(sock, PDTP_MAGIC); @@ -66,6 +67,10 @@ if(readsock(sock, vhost, value) < 0) return -1; +#ifndef NDEBUG + debug("Client sent VHOST: %s", vhost); +#endif + /* Add the connection to the client manager */ clientmgr_add_ipv4_connection(sock, addr); |
From: <tar...@pd...> - 2004-10-25 01:39:56
|
Author: tarcieri Date: 2004-10-24 19:39:41 -0600 (Sun, 24 Oct 2004) New Revision: 192 Modified: server/netevent.c Log: Updates to support latest protocol revision Modified: server/netevent.c =================================================================== --- server/netevent.c 2004-10-24 02:00:25 UTC (rev 191) +++ server/netevent.c 2004-10-25 01:39:41 UTC (rev 192) @@ -31,9 +31,13 @@ #define PTPP_MAGIC 0x50745050 #define AUTH_MAGIC 0x41555448 +/* Maximum length of vhost name */ +#define MAX_VHOST_LENGTH 1024 + static int pdtp_connection_handler(int sock, uint32_t addr) { uint16_t value; + uint8_t vhost[MAX_VHOST_LENGTH]; /* XXX Peer redirection support goes here */ writesock_int32(sock, PDTP_MAGIC); @@ -51,6 +55,17 @@ if(value != 1) return -1; + /* Read the length of the virtual host identifier */ + if(readsock_int16(sock, &value) < 0) + return -1; + + if(value > MAX_VHOST_LENGTH) + return -1; + + /* Read the virtual host identifier */ + if(readsock(sock, vhost, value) < 0) + return -1; + /* Add the connection to the client manager */ clientmgr_add_ipv4_connection(sock, addr); |
From: <tar...@pd...> - 2004-10-24 02:00:53
|
Author: tarcieri Date: 2004-10-23 20:00:25 -0600 (Sat, 23 Oct 2004) New Revision: 191 Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.html doc/draft-arcieri-peer-distributed-transfer-protocol.txt doc/draft-arcieri-peer-distributed-transfer-protocol.xml server/Client.c server/Client.h server/ClientManager.c server/ClientManager.h server/TransferManager.c Log: TransferManager and ClientManager improvements Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.html =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.html 2004-10-06 20:36:16 UTC (rev 190) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.html 2004-10-24 02:00:25 UTC (rev 191) @@ -87,7 +87,7 @@ <table summary="layout" width="66%" border="0" cellpadding="0" cellspacing="0"><tr><td><table summary="layout" width="100%" border="0" cellpadding="2" cellspacing="1"> <tr><td class="header">Network Working Group</td><td class="header">A. Arcieri, Ed.</td></tr> <tr><td class="header">Internet-Draft</td><td class="header">PDTP.org</td></tr> -<tr><td class="header">Expires: January 4, 2005</td><td class="header">July 6, 2004</td></tr> +<tr><td class="header">Expires: April 20, 2005</td><td class="header">October 20, 2004</td></tr> </table></td></tr></table> <div align="right"><span class="title"><br />Peer Distributed Transfer Protocol</span></div> <div align="right"><span class="title"><br />draft-arcieri-peer-distributed-transfer-protocol</span></div> @@ -113,7 +113,7 @@ The list of Internet-Draft Shadow Directories can be accessed at <a href='http://www.ietf.org/shadow.html'>http://www.ietf.org/shadow.html</a>.</p> <p> -This Internet-Draft will expire on January 4, 2005.</p> +This Internet-Draft will expire on April 20, 2005.</p> <h3>Copyright Notice</h3> <p> @@ -267,7 +267,7 @@ uint16 String length string Name of destination host uint16 Host port -</pre> + </pre> <p>- OR - </p><pre> @@ -309,6 +309,7 @@ </p><pre> Client responds: uint16 Protocol version +string Virtual host identifier </pre> <p> @@ -316,8 +317,15 @@ the client selects a protocol version which wasn't in the list, the client has violated the protocol and the server should terminate the connection. - + </p> +<p> +The client then sends the name of the host to which it connected. This is +similar to the "Host:" header field in HTTP, and allows PDTP servers to +provide virtual hosting capibility for multiple domain names through +a single IP. + +</p> <a name="rfc.section.1.4"></a><h4><a name="anchor5">1.4</a> Transaction format</h4> <p> Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.txt =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.txt 2004-10-06 20:36:16 UTC (rev 190) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.txt 2004-10-24 02:00:25 UTC (rev 191) @@ -2,7 +2,7 @@ Network Working Group A. Arcieri, Ed. Internet-Draft PDTP.org -Expires: January 4, 2005 July 6, 2004 +Expires: April 20, 2005 October 20, 2004 Peer Distributed Transfer Protocol @@ -28,7 +28,7 @@ The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. - This Internet-Draft will expire on January 4, 2005. + This Internet-Draft will expire on April 20, 2005. Copyright Notice @@ -52,9 +52,9 @@ -Arcieri Expires January 4, 2005 [Page 1] +Arcieri Expires April 20, 2005 [Page 1] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 Table of Contents @@ -108,9 +108,9 @@ -Arcieri Expires January 4, 2005 [Page 2] +Arcieri Expires April 20, 2005 [Page 2] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 1. Introduction @@ -164,9 +164,9 @@ -Arcieri Expires January 4, 2005 [Page 3] +Arcieri Expires April 20, 2005 [Page 3] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 1.3 Handshaking @@ -220,9 +220,9 @@ -Arcieri Expires January 4, 2005 [Page 4] +Arcieri Expires April 20, 2005 [Page 4] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 list should consist only of two 16-bit integers, each set to 1, the @@ -231,12 +231,18 @@ Client responds: uint16 Protocol version + string Virtual host identifier The client then selects which protocol version it would like to use. If the client selects a protocol version which wasn't in the list, the client has violated the protocol and the server should terminate the connection. + The client then sends the name of the host to which it connected. + This is similar to the "Host:" header field in HTTP, and allows PDTP + servers to provide virtual hosting capibility for multiple domain + names through a single IP. + 1.4 Transaction format All communication following the handshake takes the form of @@ -267,20 +273,17 @@ integer identifier for the transaction. Specific types of transactions will be enumerated below. This value is set to zero to indicate an error when responding to a client's transaction. - Otherwise, all server responses will have the same ID and serial - number as the original client's transaction. +Arcieri Expires April 20, 2005 [Page 5] + +Internet-Draft PDTP Protocol Specification October 2004 + Otherwise, all server responses will have the same ID and serial + number as the original client's transaction. - -Arcieri Expires January 4, 2005 [Page 5] - -Internet-Draft PDTP Protocol Specification July 2004 - - Transactions may or may not have a number of parameters known as "objects". The number of objects contained within a transaction are stored in the "Object count" field of the transaction header. The @@ -329,12 +332,9 @@ - - - -Arcieri Expires January 4, 2005 [Page 6] +Arcieri Expires April 20, 2005 [Page 6] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 2. Client/Server Protocol @@ -388,9 +388,9 @@ -Arcieri Expires January 4, 2005 [Page 7] +Arcieri Expires April 20, 2005 [Page 7] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 2.1.2 Command 0x2: End Download @@ -444,9 +444,9 @@ -Arcieri Expires January 4, 2005 [Page 8] +Arcieri Expires April 20, 2005 [Page 8] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 This transaction allows a client to dynamically reassign their @@ -500,9 +500,9 @@ -Arcieri Expires January 4, 2005 [Page 9] +Arcieri Expires April 20, 2005 [Page 9] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 If the concurrency value is valid, the server will respond with a @@ -556,9 +556,9 @@ -Arcieri Expires January 4, 2005 [Page 10] +Arcieri Expires April 20, 2005 [Page 10] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 The timestamp is a 48-bit string which can be broken down as follows: @@ -612,9 +612,9 @@ -Arcieri Expires January 4, 2005 [Page 11] +Arcieri Expires April 20, 2005 [Page 11] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 value representing the number of seconds since the beginning of that @@ -668,9 +668,9 @@ -Arcieri Expires January 4, 2005 [Page 12] +Arcieri Expires April 20, 2005 [Page 12] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 The 0x20 or 0x21 object is a list of hashes for each piece in the @@ -724,9 +724,9 @@ -Arcieri Expires January 4, 2005 [Page 13] +Arcieri Expires April 20, 2005 [Page 13] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 metadata rich directory listing with extended file attributes. The @@ -780,9 +780,9 @@ -Arcieri Expires January 4, 2005 [Page 14] +Arcieri Expires April 20, 2005 [Page 14] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 This transaction instructs one peer to connect to another and send @@ -836,9 +836,9 @@ -Arcieri Expires January 4, 2005 [Page 15] +Arcieri Expires April 20, 2005 [Page 15] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 2.2.1.4 Command 0x17: Terminate File Transfer @@ -892,9 +892,9 @@ -Arcieri Expires January 4, 2005 [Page 16] +Arcieri Expires April 20, 2005 [Page 16] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 This transaction is identical to the one above (0x12) except it is @@ -948,9 +948,9 @@ -Arcieri Expires January 4, 2005 [Page 17] +Arcieri Expires April 20, 2005 [Page 17] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 3. Piece Transfer Protocol @@ -1004,9 +1004,9 @@ -Arcieri Expires January 4, 2005 [Page 18] +Arcieri Expires April 20, 2005 [Page 18] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 After the protocol version and operation code, the connecting peer @@ -1060,9 +1060,9 @@ -Arcieri Expires January 4, 2005 [Page 19] +Arcieri Expires April 20, 2005 [Page 19] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 from the "Transfer Management Transactions" section, 0x15 (Report @@ -1116,9 +1116,9 @@ -Arcieri Expires January 4, 2005 [Page 20] +Arcieri Expires April 20, 2005 [Page 20] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 4. Hub Protocol @@ -1172,9 +1172,9 @@ -Arcieri Expires January 4, 2005 [Page 21] +Arcieri Expires April 20, 2005 [Page 21] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 value must be greater than or equal to the lowest version supported @@ -1228,9 +1228,9 @@ -Arcieri Expires January 4, 2005 [Page 22] +Arcieri Expires April 20, 2005 [Page 22] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 4.2.4 Command 0x201: Remove Handle @@ -1284,9 +1284,9 @@ -Arcieri Expires January 4, 2005 [Page 23] +Arcieri Expires April 20, 2005 [Page 23] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 5. Proxy Protocol @@ -1340,9 +1340,9 @@ -Arcieri Expires January 4, 2005 [Page 24] +Arcieri Expires April 20, 2005 [Page 24] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 6. Acknowledgments @@ -1396,9 +1396,9 @@ -Arcieri Expires January 4, 2005 [Page 25] +Arcieri Expires April 20, 2005 [Page 25] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 References @@ -1452,9 +1452,9 @@ -Arcieri Expires January 4, 2005 [Page 26] +Arcieri Expires April 20, 2005 [Page 26] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 Appendix A. Path format @@ -1508,9 +1508,9 @@ -Arcieri Expires January 4, 2005 [Page 27] +Arcieri Expires April 20, 2005 [Page 27] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 Appendix B. Authorization mechanisms @@ -1564,9 +1564,9 @@ -Arcieri Expires January 4, 2005 [Page 28] +Arcieri Expires April 20, 2005 [Page 28] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 Intellectual Property Statement @@ -1620,9 +1620,9 @@ -Arcieri Expires January 4, 2005 [Page 29] +Arcieri Expires April 20, 2005 [Page 29] -Internet-Draft PDTP Protocol Specification July 2004 +Internet-Draft PDTP Protocol Specification October 2004 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF @@ -1676,5 +1676,5 @@ -Arcieri Expires January 4, 2005 [Page 30] +Arcieri Expires April 20, 2005 [Page 30] Modified: doc/draft-arcieri-peer-distributed-transfer-protocol.xml =================================================================== --- doc/draft-arcieri-peer-distributed-transfer-protocol.xml 2004-10-06 20:36:16 UTC (rev 190) +++ doc/draft-arcieri-peer-distributed-transfer-protocol.xml 2004-10-24 02:00:25 UTC (rev 191) @@ -6,7 +6,7 @@ <author initials="A." surname="Arcieri" fullname="Anthony Arcieri" role="editor"> <organization>PDTP.org</organization> </author> - <date day="6" month="July" year="2004" /> + <date day="20" month="October" year="2004" /> <area>Internet</area> <keyword>I-D</keyword> <keyword>Internet-Draft</keyword> @@ -75,7 +75,7 @@ uint16 String length string Name of destination host uint16 Host port -</artwork> + </artwork> </figure> <figure> <preamble>- OR -</preamble> @@ -116,6 +116,7 @@ <artwork> Client responds: uint16 Protocol version +string Virtual host identifier </artwork> </figure> <t> @@ -123,7 +124,13 @@ the client selects a protocol version which wasn't in the list, the client has violated the protocol and the server should terminate the connection. -</t> + </t> + <t> +The client then sends the name of the host to which it connected. This is +similar to the "Host:" header field in HTTP, and allows PDTP servers to +provide virtual hosting capibility for multiple domain names through +a single IP. + </t> </section> <section title="Transaction format"> Modified: server/Client.c =================================================================== --- server/Client.c 2004-10-06 20:36:16 UTC (rev 190) +++ server/Client.c 2004-10-24 02:00:25 UTC (rev 191) @@ -13,6 +13,7 @@ /* Common headers */ #include <Collection.h> +#include <Lock.h> #include <socketops.h> #include <xmalloc.h> @@ -25,6 +26,7 @@ uint32_t addr; Collection transfers; + Lock lock; }; Client client_create(int sock, uint32_t addr) @@ -34,12 +36,17 @@ client->sock = sock; client->addr = addr; + client->lock = lock_create(LOCK_SHARED); + return client; } void client_destroy(Client client) { socket_close(client->sock); + + lock_destroy(client->lock); + xfree(client); } @@ -60,3 +67,9 @@ void client_remove_transfer(Client client, uint32_t handle) { } + +/* Used exclusively by ClientManager */ +Lock client_lock(Client client) +{ + return client->lock; +} Modified: server/Client.h =================================================================== --- server/Client.h 2004-10-06 20:36:16 UTC (rev 190) +++ server/Client.h 2004-10-24 02:00:25 UTC (rev 191) @@ -22,8 +22,4 @@ void client_add_transfer(Client client, uint32_t handle, PieceSet pieces); void client_remove_transfer(Client client, uint32_t handle); -/* These should only be used by the ClientManager */ -void client_lock(Client); -void client_unlock(Client); - #endif /* CLIENT_H */ Modified: server/ClientManager.c =================================================================== --- server/ClientManager.c 2004-10-06 20:36:16 UTC (rev 190) +++ server/ClientManager.c 2004-10-24 02:00:25 UTC (rev 191) @@ -31,6 +31,9 @@ #define INITIALIZED (client_table && client_table_lock) +/* Prototype for accessinjg client locks */ +Lock client_lock(Client client); + void clientmgr_init() { assert(!INITIALIZED); @@ -94,35 +97,39 @@ client_destroy(client); } -/* XXX This interface will need to be refactored to support fine grained locking */ -void clientmgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) +/* Invoke the given callback after locking the given client as specified */ +void clientmgr_client_op(int uid, LockType locktype, void (*callback)(Client, void *arg), void *arg) { Client client; - - assert(INITIALIZED); - lock_writer_acquire(client_table_lock); - client = (Client)collection_lookup(client_table, uid); - + assert(INITIALIZED); + + lock_reader_acquire(client_table_lock); + + client = (Client)collection_lookup(client_table, uid); + /* Check to see internal structures are consistent */ assert(client != 0); + + switch(locktype) { + case LOCK_SHARED: + lock_reader_acquire(client_lock(client)); + break; + case LOCK_EXCL: + lock_writer_acquire(client_lock(client)); + break; + } + + callback(client, arg); - client_add_transfer(client, file_handle, remaining_pieces); - lock_writer_release(client_table_lock); + switch(locktype) { + case LOCK_SHARED: + lock_reader_release(client_lock(client)); + break; + case LOCK_EXCL: + lock_writer_release(client_lock(client)); + break; + } + + lock_reader_release(client_table_lock); } - -void clientmgr_remove_transfer(int uid, uint32_t file_handle) -{ - Client client; - - assert(INITIALIZED); - - lock_writer_acquire(client_table_lock); - client = (Client)collection_lookup(client_table, uid); - - /* Check to see internal structures are consistent */ - assert(client != 0); - - client_remove_transfer(client, file_handle); - lock_writer_release(client_table_lock); -} Modified: server/ClientManager.h =================================================================== --- server/ClientManager.h 2004-10-06 20:36:16 UTC (rev 190) +++ server/ClientManager.h 2004-10-24 02:00:25 UTC (rev 191) @@ -8,17 +8,24 @@ #include <machdep.h> +/* Common headers */ +#include <Lock.h> + /* Local headers */ +#include "Client.h" #include "PieceSet.h" -void clientmgr_init(); -void clientmgr_reinit(); -void clientmgr_destroy(); +void clientmgr_init(void); +void clientmgr_reinit(void); +void clientmgr_destroy(void); +/* Add a new client to the client manager with the given IPv4 address */ int clientmgr_add_ipv4_connection(int sock, uint32_t addr); + +/* Remove the client associated with the given socket from the client manager */ void clientmgr_remove_connection(int sock); -void clientmgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces); -void clientmgr_remove_transfer(int uid, uint32_t file_handle); +/* Invoke the given callback after locking the given client as specified */ +void clientmgr_client_op(int uid, LockType, void (*callback)(Client, void *arg), void *arg); -#endif +#endif /* CLIENTMANAGER_H */ Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-10-06 20:36:16 UTC (rev 190) +++ server/TransferManager.c 2004-10-24 02:00:25 UTC (rev 191) @@ -21,6 +21,7 @@ #include <xmalloc.h> /* Local headers */ +#include "Client.h" #include "ClientManager.h" #include "PieceSet.h" #include "TransferManager.h" @@ -170,20 +171,44 @@ return ret; } +struct addxfer_args { + uint32_t file_handle; + PieceSet remaining_pieces; +}; + +static void xfermgr_add(Client client, void *arg) +{ + struct addxfer_args *args = (struct addxfer_args *)arg; + + client_add_transfer(client, args->file_handle, args->remaining_pieces); +} + void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) { + struct addxfer_args args; + assert(INITIALIZED); #ifndef DEBUG debug("Client %d has requested to transfer file %d", uid, file_handle); #endif - clientmgr_add_transfer(uid, file_handle, remaining_pieces); + args.file_handle = file_handle; + args.remaining_pieces = remaining_pieces; + + clientmgr_client_op(uid, LOCK_EXCL, xfermgr_add, &args); } +static void xfermgr_remove(Client client, void *arg) +{ + uint32_t file_handle = *(uint32_t *)arg; + + client_remove_transfer(client, file_handle); +} + void xfermgr_remove_transfer(int uid, uint32_t file_handle) { assert(INITIALIZED); - clientmgr_remove_transfer(uid, file_handle); + clientmgr_client_op(uid, LOCK_EXCL, xfermgr_remove, &file_handle); } |
From: <tar...@pd...> - 2004-10-06 20:36:29
|
Author: tarcieri Date: 2004-10-06 14:36:16 -0600 (Wed, 06 Oct 2004) New Revision: 190 Modified: server/Client.h server/ClientManager.c server/TransferManager.c Log: ClientManager and TransferManager updates Modified: server/Client.h =================================================================== --- server/Client.h 2004-10-05 18:53:49 UTC (rev 189) +++ server/Client.h 2004-10-06 20:36:16 UTC (rev 190) @@ -8,6 +8,9 @@ #include <machdep.h> +/* Local headers */ +#include "PieceSet.h" + typedef struct _Client *Client; Client client_create(int sock, uint32_t addr); @@ -16,6 +19,9 @@ int client_sock(Client); uint32_t client_addr(Client); +void client_add_transfer(Client client, uint32_t handle, PieceSet pieces); +void client_remove_transfer(Client client, uint32_t handle); + /* These should only be used by the ClientManager */ void client_lock(Client); void client_unlock(Client); Modified: server/ClientManager.c =================================================================== --- server/ClientManager.c 2004-10-05 18:53:49 UTC (rev 189) +++ server/ClientManager.c 2004-10-06 20:36:16 UTC (rev 190) @@ -97,14 +97,32 @@ /* XXX This interface will need to be refactored to support fine grained locking */ void clientmgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) { + Client client; + assert(INITIALIZED); - + lock_writer_acquire(client_table_lock); + client = (Client)collection_lookup(client_table, uid); + + /* Check to see internal structures are consistent */ + assert(client != 0); + + client_add_transfer(client, file_handle, remaining_pieces); + lock_writer_release(client_table_lock); } void clientmgr_remove_transfer(int uid, uint32_t file_handle) { + Client client; + assert(INITIALIZED); - + lock_writer_acquire(client_table_lock); + client = (Client)collection_lookup(client_table, uid); + + /* Check to see internal structures are consistent */ + assert(client != 0); + + client_remove_transfer(client, file_handle); + lock_writer_release(client_table_lock); } Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-10-05 18:53:49 UTC (rev 189) +++ server/TransferManager.c 2004-10-06 20:36:16 UTC (rev 190) @@ -21,6 +21,7 @@ #include <xmalloc.h> /* Local headers */ +#include "ClientManager.h" #include "PieceSet.h" #include "TransferManager.h" @@ -176,9 +177,13 @@ #ifndef DEBUG debug("Client %d has requested to transfer file %d", uid, file_handle); #endif + + clientmgr_add_transfer(uid, file_handle, remaining_pieces); } void xfermgr_remove_transfer(int uid, uint32_t file_handle) { assert(INITIALIZED); + + clientmgr_remove_transfer(uid, file_handle); } |
From: <tar...@pd...> - 2004-10-05 18:54:10
|
Author: tarcieri Date: 2004-10-05 12:53:49 -0600 (Tue, 05 Oct 2004) New Revision: 189 Added: server/Transfer.c server/Transfer.h Modified: hub/DirList.h hub/FileEntry.h hub/FileHasher.h hub/FileHashes.h hub/FileManager.h hub/squall-hub.h server/Client.c server/Client.h server/ClientManager.c server/ClientManager.h server/HubConnection.h server/Makefile.in server/PieceSet.h server/TransferManager.h server/clienttxn.h server/hubtxn.h server/netevent.h server/squall-server.h Log: Source cleanups and transfer manager work Modified: hub/DirList.h =================================================================== --- hub/DirList.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/DirList.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,10 +1,11 @@ -#ifndef DIRLIST_H -#define DIRLIST_H - /** * @file DirList.h * @brief Abstract directory listing interface for VFS monitor */ + +#ifndef DIRLIST_H +#define DIRLIST_H + #include <machdep.h> /* Common headers */ Modified: hub/FileEntry.h =================================================================== --- hub/FileEntry.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/FileEntry.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,3 +1,8 @@ +/** + * @file FileEntry.h + * @brief File metadata object for file manager + */ + #ifndef FILEENTRY_H #define FILEENTRY_H Modified: hub/FileHasher.h =================================================================== --- hub/FileHasher.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/FileHasher.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,3 +1,8 @@ +/** + * @file FileHasher.h + * @brief Interface to the file hasher service + */ + #ifndef FILEHASHER_H #define FILEHASHER_H Modified: hub/FileHashes.h =================================================================== --- hub/FileHashes.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/FileHashes.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,3 +1,8 @@ +/** + * @file FileHashes.h + * @brief Object for storing file hash lists + */ + #ifndef FILEHASHES_H #define FILEHASHES_H Modified: hub/FileManager.h =================================================================== --- hub/FileManager.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/FileManager.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,3 +1,8 @@ +/** + * @file FileManager.h + * @brief Manages files being served + */ + #ifndef FILEMANAGER_H #define FILEMANAGER_H @@ -10,10 +15,6 @@ #include "FileEntry.h" #include "FileHashes.h" -/** - * @file FileManager.h - * @brief Manages files being served - */ void filemgr_init(); void filemgr_reinit(); void filemgr_destroy(); Modified: hub/squall-hub.h =================================================================== --- hub/squall-hub.h 2004-09-30 21:27:34 UTC (rev 188) +++ hub/squall-hub.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,13 +1,13 @@ /** - * @file squallhub.h - * @brief Application-specific settings for squallhub + * @file squall-hub.h + * @brief Application-specific settings for Squall Hub */ -#ifndef SQUALLHUB_H -#define SQUALLHUB_H +#ifndef SQUALL_HUB_H +#define SQUALL_HUB_H /* Program information */ -#define PACKAGE "squallhub" +#define PACKAGE "squall-hub" #define VERSION "M1-preRC1" /* Maximum number of clients to accept */ @@ -21,4 +21,4 @@ #define DEFAULT_MAX_INACTIVE_THREADS 8 #define DEFAULT_INITIAL_THREADS 1 -#endif /* PDTPD_H */ +#endif /* SQUALL_HUB_H */ Modified: server/Client.c =================================================================== --- server/Client.c 2004-09-30 21:27:34 UTC (rev 188) +++ server/Client.c 2004-10-05 18:53:49 UTC (rev 189) @@ -12,15 +12,19 @@ #include <machdep.h> /* Common headers */ +#include <Collection.h> #include <socketops.h> #include <xmalloc.h> /* Local headers */ #include "Client.h" +#include "PieceSet.h" struct _Client { int sock; uint32_t addr; + + Collection transfers; }; Client client_create(int sock, uint32_t addr) @@ -48,3 +52,11 @@ { return client->addr; } + +void client_add_transfer(Client client, uint32_t handle, PieceSet pieces) +{ +} + +void client_remove_transfer(Client client, uint32_t handle) +{ +} Modified: server/Client.h =================================================================== --- server/Client.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/Client.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,3 +1,8 @@ +/** + * @file Client.h + * @brief Structure for storing client metadata + */ + #ifndef CLIENT_H #define CLIENT_H @@ -2,6 +7,3 @@ #include <machdep.h> -/** - * @file Client.h - * @brief Structure for storing client metadata - */ + typedef struct _Client *Client; Modified: server/ClientManager.c =================================================================== --- server/ClientManager.c 2004-09-30 21:27:34 UTC (rev 188) +++ server/ClientManager.c 2004-10-05 18:53:49 UTC (rev 189) @@ -24,6 +24,7 @@ /* Local headers */ #include "Client.h" #include "ClientManager.h" +#include "PieceSet.h" static Collection client_table = 0; static Lock client_table_lock = 0; @@ -92,3 +93,18 @@ client_destroy(client); } + +/* XXX This interface will need to be refactored to support fine grained locking */ +void clientmgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) +{ + assert(INITIALIZED); + + +} + +void clientmgr_remove_transfer(int uid, uint32_t file_handle) +{ + assert(INITIALIZED); + + +} Modified: server/ClientManager.h =================================================================== --- server/ClientManager.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/ClientManager.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,9 +1,16 @@ -#ifndef CLIENTMANAGER_H -#define CLIENTMANAGER_H /** * @file ClientManager.h * @brief Central structure for storing all client metadata */ + +#ifndef CLIENTMANAGER_H +#define CLIENTMANAGER_H + +#include <machdep.h> + +/* Local headers */ +#include "PieceSet.h" + void clientmgr_init(); void clientmgr_reinit(); void clientmgr_destroy(); @@ -11,4 +18,7 @@ int clientmgr_add_ipv4_connection(int sock, uint32_t addr); void clientmgr_remove_connection(int sock); +void clientmgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces); +void clientmgr_remove_transfer(int uid, uint32_t file_handle); + #endif Modified: server/HubConnection.h =================================================================== --- server/HubConnection.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/HubConnection.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,10 +1,11 @@ +/** + * @file HubConnection.h + * @brief Code for connecting to and communicating with a hub + */ + #ifndef HUBCONNECTION_H #define HUBCONNECTION_H -/** - * @file SourceConnection.h - * @brief Code for connecting to and communicating with a hub - */ #include <Transaction.h> void hubcxn_init(); Modified: server/Makefile.in =================================================================== --- server/Makefile.in 2004-09-30 21:27:34 UTC (rev 188) +++ server/Makefile.in 2004-10-05 18:53:49 UTC (rev 189) @@ -7,6 +7,7 @@ ClientManager.o \ HubConnection.o \ PieceSet.o \ + Transfer.o \ TransferManager.o \ clienttxn.o \ hubtxn.o \ Modified: server/PieceSet.h =================================================================== --- server/PieceSet.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/PieceSet.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,10 +1,11 @@ +/** + * @file PieceSet.h + * @brief Structure for storing lists of pieces + */ + #ifndef PIECESET_H #define PIECESET_H -/** - * @file PieceSet.h - * @brief Bit vector piece set management. - */ typedef struct _PieceSet *PieceSet; /** Creates an empty piece set that can represent pieces from 0 to size. */ Added: server/Transfer.c =================================================================== --- server/Transfer.c 2004-09-30 21:27:34 UTC (rev 188) +++ server/Transfer.c 2004-10-05 18:53:49 UTC (rev 189) @@ -0,0 +1,20 @@ +/** + @file Transfer.c + @brief Structure for storing transfer information +*/ +/* + Copyright (C)2004 Anthony Arcieri + All rights reserved. + + For licensing information, please see the file LICENSE +*/ + +#include <machdep.h> + +/* Local headers */ +#include "PieceSet.h" +#include "Transfer.h" + +struct _Transfer { + PieceSet remaining; +}; Added: server/Transfer.h =================================================================== --- server/Transfer.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/Transfer.h 2004-10-05 18:53:49 UTC (rev 189) @@ -0,0 +1,11 @@ +/** + * @file Transfer.h + * @brief Structure for storing transfer information + */ + +#ifndef TRANSFER_H +#define TRANSFER_H + +typedef struct _Transfer *Transfer; + +#endif /* TRANSFER_H */ Modified: server/TransferManager.h =================================================================== --- server/TransferManager.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/TransferManager.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,13 +1,14 @@ -#ifndef TRANSFERMANAGER_H -#define TRANSFERMANAGER_H - /** * @file TransferManager.h * @brief State machine for all file transfers */ +#ifndef TRANSFERMANAGER_H +#define TRANSFERMANAGER_H + #include <machdep.h> +/* Local headers */ #include "PieceSet.h" void xfermgr_init(void); @@ -22,5 +23,5 @@ void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces); void xfermgr_remove_transfer(int uid, uint32_t file_handle); - + #endif /* TRANSFERMANAGER_H */ Modified: server/clienttxn.h =================================================================== --- server/clienttxn.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/clienttxn.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,15 +1,16 @@ -#ifndef CLIENTTXN_H -#define CLIENTTXN_H - /** * @file clienttxn.h * @brief Squall Server's handlers for client transactions */ + +#ifndef CLIENTTXN_H +#define CLIENTTXN_H + #include <Transaction.h> void clienttxn_init(); void clienttxn_destroy(); int clienttxn_exec(int sock, TransactionIn t); - -#endif /* CLIENTTXN */ + +#endif /* CLIENTTXN_H */ Modified: server/hubtxn.h =================================================================== --- server/hubtxn.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/hubtxn.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,10 +1,11 @@ -#ifndef HUBTXN_H -#define HUBTXN_H - /** * @file hubtxn.h * @brief Squall Server's's handlers for hub transactions */ + +#ifndef HUBTXN_H +#define HUBTXN_H + #include <Transaction.h> void hubtxn_init(); Modified: server/netevent.h =================================================================== --- server/netevent.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/netevent.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,10 +1,11 @@ -#ifndef NETEVENT_H -#define NETEVENT_H /** * @file netevent.h * @brief Network event handlers (invoked by dispatcher) */ - + +#ifndef NETEVENT_H +#define NETEVENT_H + #include <msgval.h> /* Incoming connection handler */ Modified: server/squall-server.h =================================================================== --- server/squall-server.h 2004-09-30 21:27:34 UTC (rev 188) +++ server/squall-server.h 2004-10-05 18:53:49 UTC (rev 189) @@ -1,13 +1,13 @@ /** * @file squall.h - * @brief Application-specific settings for squall + * @brief Application-specific settings for Squall Server */ -#ifndef SQUALL_H -#define SQUALL_H +#ifndef SQUALL_SERVER_H +#define SQUALL_SERVER_H /* Program information */ -#define PACKAGE "squall" +#define PACKAGE "squall-server" #define VERSION "M1-preRC1" /* Maximum number of clients to accept */ @@ -16,4 +16,4 @@ /* Default port to bind to */ #define DEFAULT_PORT 40 -#endif /* SQUALL_H */ +#endif /* SQUALL_SERVER_H */ |
From: <tar...@pd...> - 2004-09-30 21:27:44
|
Author: tarcieri Date: 2004-09-30 15:27:34 -0600 (Thu, 30 Sep 2004) New Revision: 188 Modified: server/TransferManager.c server/clienttxn.c Log: Transfer manager updates Modified: server/TransferManager.c =================================================================== --- server/TransferManager.c 2004-09-21 19:45:42 UTC (rev 187) +++ server/TransferManager.c 2004-09-30 21:27:34 UTC (rev 188) @@ -172,6 +172,10 @@ void xfermgr_add_transfer(int uid, uint32_t file_handle, PieceSet remaining_pieces) { assert(INITIALIZED); + +#ifndef DEBUG + debug("Client %d has requested to transfer file %d", uid, file_handle); +#endif } void xfermgr_remove_transfer(int uid, uint32_t file_handle) Modified: server/clienttxn.c =================================================================== --- server/clienttxn.c 2004-09-21 19:45:42 UTC (rev 187) +++ server/clienttxn.c 2004-09-30 21:27:34 UTC (rev 188) @@ -125,6 +125,7 @@ } for(i = 0; i < piece_count; i++) { + /* AUDIT and macro wrap - buffer overflow potential */ memcpy(&v32, bptr + i * 8, 4); range_low = ntohl(v32); @@ -142,7 +143,7 @@ } } - xfermgr_add_transfer(sock, 0, set); + xfermgr_add_transfer(sock, handle, set); reply = transaction_create(TXN_REPLY, transaction_id(txn), 1); transaction_set_serial(reply, transaction_serial(txn)); @@ -150,8 +151,6 @@ transaction_write(sock, reply); transaction_out_destroy(reply); - /* XXX Dispatch event to transfer manager */ - return 0; } |