diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-06-22 15:26:18 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-06-22 15:26:18 +0000 |
| commit | d02d80d9e99e81e06cfb560487a46ed9eed092a2 (patch) | |
| tree | 940626013de8fcf7ba672f977766575103847978 /src/PeerConnection.cc | |
| parent | 70ff0c0b3b10e5b58714757a3b6aa55e2569c511 (diff) | |
2006-06-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To make a listening socket non-block:
* src/SocketCore.h
(setNonBlockingMode): New function.
* src/SocketCore.cc
(setNonBlockingMode): New function.
(beginListen): Added a call to setNonBlockingMode().
(acceptConnection): Call setNonBlockingMode().
(setBlockingMode): Updated.
To handle tracker's NAT-checking:
* src/PeerConnection.cc
(receiveHandshake): 'msg' param is filled with received data and
its length is assigned to 'length' param, even if all handshake
message is not yet received.
* src/PeerInteractionCommand.cc
(executeInternal): Use peerInteraction->receiveHandshake(true)
when
a new peer connects to localhost.
A call to peerInteraction->sendHandshake() was removed because
it is called from peerInteraction->receiveHandshake(true).
* src/PeerInteraction.h
(quickReplied): New variable.
(receiveHandshake): Added an argument.
* src/PeerInteraction.cc
(PeerInteraction): Added the initialization of quickReplied.
(receiveHandshake): Send handshake message as soon as the info
hash
in a handshake message from a peer is correct.
To change the random part of peer id and key parameter:
* src/TorrentMan.h
(key): New variable.
* src/TorrentMan.cc
(setupInternal1): Use Util::randomAlpha() to generate random
part
of peer id, which is now "-aria2-"+13 alphabet
characters([A-Za-z]).
key is also generated by Util::randomAlpha() and it is now 8
character
long.
* src/Util.h
(randomAlpha): New function.
* src/Util.cc
(randomAlpha): New function.
* src/TrackerWatcherCommand.cc
(execute): In a tracker request: Use torrentMan->key as key
parameter.
Added no_peer_id=1.
Set snubbing flag to false when a choke message is received from
a
snubbed peer.
* src/ChokeMessage.cc
(receivedAction): Set snubbing flag to false.
Diffstat (limited to 'src/PeerConnection.cc')
| -rw-r--r-- | src/PeerConnection.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc index 42d64240..b8d3fee9 100644 --- a/src/PeerConnection.cc +++ b/src/PeerConnection.cc @@ -101,6 +101,7 @@ bool PeerConnection::receiveMessage(char* msg, int& length) { bool PeerConnection::receiveHandshake(char* msg, int& length) { if(!socket->isReadable(0)) { + length = 0; return false; } int remain = HANDSHAKE_MESSAGE_LENGTH-resbufLength; @@ -110,14 +111,19 @@ bool PeerConnection::receiveHandshake(char* msg, int& length) { // we got EOF throw new DlAbortEx(EX_EOF_FROM_PEER); } + bool retval; if(remain != temp) { - resbufLength += temp; - return false; + retval = false; + } else { + retval = true; } + resbufLength += temp; // we got whole handshake payload - resbufLength = 0; - - memcpy(msg, resbuf, HANDSHAKE_MESSAGE_LENGTH); - length = HANDSHAKE_MESSAGE_LENGTH; - return true; + int writeLength = resbufLength > length ? length : resbufLength; + memcpy(msg, resbuf, writeLength); + length = writeLength; + if(retval) { + resbufLength = 0; + } + return retval; } |
