summaryrefslogtreecommitdiff
path: root/src/PeerConnection.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-01-09 23:57:07 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-01-09 23:57:07 +0900
commit3e67079087577e8f3f4918c2c0822fc0420dc190 (patch)
tree62f78c43c5427ef5eac8893b2e8bb1ba24a46f8e /src/PeerConnection.cc
parent1818f2ed5537232316d8a9aa21d6fa6318c273a9 (diff)
Rewritten NAT check handling.
We simplified PeerConnection::receiveHandshake(). DefaultBtMessageReceiver and PeerReceiverHandshakeCommand look PeerConnection's buffer and do NAT check handling themselves.
Diffstat (limited to 'src/PeerConnection.cc')
-rw-r--r--src/PeerConnection.cc46
1 files changed, 16 insertions, 30 deletions
diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc
index 05b04351..b894f8ae 100644
--- a/src/PeerConnection.cc
+++ b/src/PeerConnection.cc
@@ -182,36 +182,22 @@ bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
("More than BtHandshakeMessage::MESSAGE_LENGTH bytes are buffered.");
}
bool retval = true;
- if(((!prevPeek_ && peek) || (prevPeek_ && !peek)) && resbufLength_) {
- // We have data in previous peek.
- // There is a chance that socket is readable because of EOF, for example,
- // official bttrack shutdowns socket after sending first 48 bytes of
- // handshake in its NAT checking.
- // So if there are data in resbuf_, return it without checking socket
- // status.
- //
- // (!prevPeek_ && peek) effectively returns preset buffer.
- prevPeek_ = false;
- retval = BtHandshakeMessage::MESSAGE_LENGTH <= resbufLength_;
- } else {
- prevPeek_ = peek;
- size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength_;
- if(remaining > 0) {
- size_t temp = remaining;
- readData(resbuf_+resbufLength_, remaining, encryptionEnabled_);
- if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
- // we got EOF
- A2_LOG_DEBUG
- (fmt("CUID#%lld - In PeerConnection::receiveHandshake(), remain=%lu",
- cuid_,
- static_cast<unsigned long>(temp)));
- peer_->setDisconnectedGracefully(true);
- throw DL_ABORT_EX(EX_EOF_FROM_PEER);
- }
- resbufLength_ += remaining;
- if(BtHandshakeMessage::MESSAGE_LENGTH > resbufLength_) {
- retval = false;
- }
+ size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength_;
+ if(remaining > 0) {
+ size_t temp = remaining;
+ readData(resbuf_+resbufLength_, remaining, encryptionEnabled_);
+ if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
+ // we got EOF
+ A2_LOG_DEBUG
+ (fmt("CUID#%lld - In PeerConnection::receiveHandshake(), remain=%lu",
+ cuid_,
+ static_cast<unsigned long>(temp)));
+ peer_->setDisconnectedGracefully(true);
+ throw DL_ABORT_EX(EX_EOF_FROM_PEER);
+ }
+ resbufLength_ += remaining;
+ if(BtHandshakeMessage::MESSAGE_LENGTH > resbufLength_) {
+ retval = false;
}
}
size_t writeLength = std::min(resbufLength_, dataLength);