2008-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added _incoming member to Peer class and made it true if the 
peer
	initiated connection. Don't add those peer to UTPex message.
	If extended handshake is received, assign _incoming to false.
	* src/DefaultBtInteractive.cc
	* src/HandshakeExtensionMessage.cc
	* src/Peer.cc
	* src/Peer.h
	* src/PeerListenCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-09-02 11:22:47 +00:00
parent d4215a82b7
commit 46f0e018d4
6 changed files with 35 additions and 5 deletions

View File

@ -1,3 +1,14 @@
2008-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added _incoming member to Peer class and made it true if the peer
initiated connection. Don't add those peer to UTPex message.
If extended handshake is received, assign _incoming to false.
* src/DefaultBtInteractive.cc
* src/HandshakeExtensionMessage.cc
* src/Peer.cc
* src/Peer.h
* src/PeerListenCommand.cc
2008-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made files whose name ends with ".gz", ".tgz" not inflated by Content

View File

@ -402,7 +402,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
for(Peers::const_iterator i = peers.begin();
i != peers.end() && max; ++i) {
const PeerHandle& cpeer = *i;
if(peer->ipaddr != cpeer->ipaddr &&
if(peer->ipaddr != cpeer->ipaddr && !cpeer->isIncomingPeer() &&
!cpeer->getFirstContactTime().elapsed(interval)) {
m->addFreshPeer(cpeer);
--max;

View File

@ -102,6 +102,7 @@ void HandshakeExtensionMessage::doReceivedAction()
{
if(_tcpPort > 0) {
_peer->port = _tcpPort;
_peer->setIncomingPeer(false);
}
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
itr != _extensions.end(); ++itr) {

View File

@ -45,12 +45,13 @@ namespace aria2 {
#define BAD_CONDITION_INTERVAL 10
Peer::Peer(std::string ipaddr, uint16_t port):
Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
ipaddr(ipaddr),
port(port),
_badConditionStartTime(0),
_seeder(false),
_res(0)
_res(0),
_incoming(incoming)
{
resetStatus();
std::string idSeed = ipaddr+":"+Util::uitos(port);
@ -460,4 +461,14 @@ uint64_t Peer::getCompletedLength() const
return _res->getCompletedLength();
}
bool Peer::isIncomingPeer() const
{
return _incoming;
}
void Peer::setIncomingPeer(bool incoming)
{
_incoming = incoming;
}
} // namespace aria2

View File

@ -69,12 +69,15 @@ private:
PeerSessionResource* _res;
// If true, port is assumed not to be a listening port.
bool _incoming;
// Before calling updateSeeder(), make sure that
// allocateSessionResource() is called and _res is created.
// Otherwise assertion fails.
void updateSeeder();
public:
Peer(std::string ipaddr, uint16_t port);
Peer(std::string ipaddr, uint16_t port, bool incoming = false);
~Peer();
@ -237,6 +240,10 @@ public:
const Time& getLastAmUnchoking() const;
uint64_t getCompletedLength() const;
bool isIncomingPeer() const;
void setIncomingPeer(bool incoming);
};
typedef SharedHandle<Peer> PeerHandle;

View File

@ -101,7 +101,7 @@ bool PeerListenCommand::execute() {
// here.
peerSocket->setBlockingMode();
PeerHandle peer(new Peer(peerInfo.first, 0));
PeerHandle peer(new Peer(peerInfo.first, peerInfo.second, true));
int32_t cuid = CUIDCounterSingletonHolder::instance()->newID();
Command* command =
new ReceiverMSEHandshakeCommand(cuid, peer, e, peerSocket);