X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ftransfer.c;h=0bf759ed440b4146e99b461bcda357952e534378;hb=d9f89ef5daa6375fc4ff257826fa39562fbe3ac3;hp=f4f0fef99216eb464b4eee8b2a93bb7bf62419fb;hpb=18f56d133715db3184ce7f11c34d4113268a722f;p=doldaconnect.git diff --git a/daemon/transfer.c b/daemon/transfer.c index f4f0fef..0bf759e 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -40,6 +40,8 @@ static void killfilter(struct transfer *transfer); +unsigned long long bytesupload = 0; +unsigned long long bytesdownload = 0; struct transfer *transfers = NULL; int numtransfers = 0; GCBCHAIN(newtransfercb, struct transfer *); @@ -78,6 +80,8 @@ void freetransfer(struct transfer *transfer) free(transfer->filterbuf); if(transfer->hash != NULL) freehash(transfer->hash); + if(transfer->exitstatus != NULL) + free(transfer->exitstatus); if(transfer->localend != NULL) { transfer->localend->readcb = NULL; @@ -151,6 +155,18 @@ struct transfer *finddownload(wchar_t *peerid) return(transfer); } +struct transfer *hasupload(struct fnet *fnet, wchar_t *peerid) +{ + struct transfer *transfer; + + for(transfer = transfers; transfer != NULL; transfer = transfer->next) + { + if((transfer->dir == TRNSD_UP) && (transfer->fnet == fnet) && !wcscmp(transfer->peerid, peerid)) + break; + } + return(transfer); +} + struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data) { struct transfer *transfer; @@ -240,6 +256,7 @@ void transferputdata(struct transfer *transfer, void *buf, size_t size) time(&transfer->activity); sockqueue(transfer->localend, buf, size); transfer->curpos += size; + bytesdownload += size; CBCHAINDOCB(transfer, trans_p, transfer); } @@ -279,6 +296,7 @@ void *transfergetdata(struct transfer *transfer, size_t *size) buf = srealloc(buf, *size); } transfer->curpos += *size; + bytesupload += *size; CBCHAINDOCB(transfer, trans_p, transfer); return(buf); } @@ -339,7 +357,10 @@ static int tryreq(struct transfer *transfer) } } if(peer != NULL) + { + time(&transfer->lastreq); return(fn->fnet->reqconn(peer)); + } return(1); } @@ -559,6 +580,17 @@ static char *findfilter(struct passwd *pwd) return(NULL); } +static void handletranscmd(struct transfer *transfer, wchar_t *cmd, wchar_t *arg) +{ + if(!wcscmp(cmd, L"status")) { + if(arg == NULL) + arg = L""; + if(transfer->exitstatus != NULL) + free(transfer->exitstatus); + transfer->exitstatus = swcsdup(arg); + } +} + static void filterread(struct socket *sk, struct transfer *transfer) { char *buf, *p, *p2; @@ -569,7 +601,7 @@ static void filterread(struct socket *sk, struct transfer *transfer) return; bufcat(transfer->filterbuf, buf, bufsize); free(buf); - if((p = memchr(transfer->filterbuf, '\n', transfer->filterbufdata)) != NULL) + while((p = memchr(transfer->filterbuf, '\n', transfer->filterbufdata)) != NULL) { *(p++) = 0; if((p2 = strchr(transfer->filterbuf, ' ')) != NULL) @@ -580,8 +612,9 @@ static void filterread(struct socket *sk, struct transfer *transfer) if(p2 != NULL) { if((arg = icmbstowcs(p2, NULL)) == NULL) - flog(LOG_WARNING, "filter sent a string which could not be converted into the local charset: %s: %s", transfer->filterbuf, strerror(errno)); + flog(LOG_WARNING, "filter sent a string which could not be converted into the local charset: %s: %s", p2, strerror(errno)); } + handletranscmd(transfer, cmd, arg); CBCHAINDOCB(transfer, trans_filterout, transfer, cmd, arg); if(arg != NULL) free(arg); @@ -596,6 +629,8 @@ static void filterread(struct socket *sk, struct transfer *transfer) static void filterexit(pid_t pid, int status, void *data) { struct transfer *transfer; + struct fnet *fnet; + wchar_t *peerid; for(transfer = transfers; transfer != NULL; transfer = transfer->next) { @@ -603,12 +638,14 @@ static void filterexit(pid_t pid, int status, void *data) { transfer->filter = -1; killfilter(transfer); + fnet = transfer->fnet; + peerid = swcsdup(transfer->peerid); if(WEXITSTATUS(status)) - { resettransfer(transfer); - } else { + else freetransfer(transfer); - } + trytransferbypeer(fnet, peerid); + free(peerid); break; } } @@ -761,10 +798,23 @@ static int run(void) static struct configvar myvars[] = { + /** The maximum number of simultaneously permitted uploads. A + * common hub rule is that you will need at least as many slots as + * the number of hubs to which you are connected. */ {CONF_VAR_INT, "slots", {.num = 3}}, + /** The TOS value to use for upload connections (see the TOS + * VALUES section). */ {CONF_VAR_INT, "ultos", {.num = SOCK_TOS_MAXTP}}, + /** The TOS value to use for download connections (see the TOS + * VALUES section). */ {CONF_VAR_INT, "dltos", {.num = SOCK_TOS_MAXTP}}, + /** The name of the filter script (see the FILES section for + * lookup information). */ {CONF_VAR_STRING, "filter", {.str = L"dc-filter"}}, + /** If true, only one upload is allowed per remote peer. This + * option is still experimental, so it is recommended to leave it + * off. */ + {CONF_VAR_BOOL, "ulquota", {.num = 0}}, {CONF_VAR_END} };