clients.cpp File Reference

Implementation of clients-related classes. More...

#include <hn/hnprec.h>
#include "clients.h"
#include "ed2k.h"
#include "serverlist.h"
#include "creditsdb.h"
#include "parser.h"
#include "clientext.h"
#include <hn/metadb.h>
#include <hn/sharedfile.h>
#include <hn/partdata.h>
#include <hn/fileslist.h>
#include <hn/lambda_placeholders.h>
#include <hn/hydranode.h>
#include <hn/ssocket.h>
#include <hn/hashsetmaker.h>
#include <boost/lambda/bind.hpp>

Go to the source code of this file.


Namespaces

namespace  Detail

Signals emitted from Client object

These are declared here, as global, because we cannot use static data in modules.

boost::signal< void(Client *,
uint32_t) 
changeId )
 Emitted when a client changes it's ID.
boost::signal< bool(const
Hash< ED2KHash > &, IPV4Address,
IPV4Address, bool) > 
foundSource
 Emitted when a new source is discovered by a client.
boost::signal< void(IPV4Address)> foundServer
 Emitted when a new server is discovered.

Enumerations

enum  Ed2k_ClientConstants {
  SOURCE_REASKTIME = 30*60*1000, UDP_TIMEOUT = 30000, SOCKET_TIMEOUT = 30000, CALLBACK_TIMEOUT = 60000,
  CONNECT_TIMEOUT = 15000
}
 Here's a collection of things that can be used to tweak the ed2k inter-client communication procedures. More...

Functions

 IMPLEMENT_EVENT_TABLE (Client, Client *, ClientEvent)
 DECLARE_PACKET_HANDLER (Client, Hello)
 DECLARE_PACKET_HANDLER (Client, MuleInfo)
 DECLARE_PACKET_HANDLER (Client, ReqFile)
 DECLARE_PACKET_HANDLER (Client, SetReqFileId)
 DECLARE_PACKET_HANDLER (Client, ReqHashSet)
 DECLARE_PACKET_HANDLER (Client, StartUploadReq)
 DECLARE_PACKET_HANDLER (Client, ReqChunks)
 DECLARE_PACKET_HANDLER (Client, CancelTransfer)
 DECLARE_PACKET_HANDLER (Client, FileName)
 DECLARE_PACKET_HANDLER (Client, FileDesc)
 DECLARE_PACKET_HANDLER (Client, FileStatus)
 DECLARE_PACKET_HANDLER (Client, NoFile)
 DECLARE_PACKET_HANDLER (Client, HashSet)
 DECLARE_PACKET_HANDLER (Client, AcceptUploadReq)
 DECLARE_PACKET_HANDLER (Client, QueueRanking)
 DECLARE_PACKET_HANDLER (Client, MuleQueueRank)
 DECLARE_PACKET_HANDLER (Client, DataChunk)
 DECLARE_PACKET_HANDLER (Client, PackedChunk)
 DECLARE_PACKET_HANDLER (Client, SourceExchReq)
 DECLARE_PACKET_HANDLER (Client, AnswerSources)
 DECLARE_PACKET_HANDLER (Client, Message)
 DECLARE_PACKET_HANDLER (Client, ChangeId)
 DECLARE_PACKET_HANDLER (Client, SecIdentState)
 DECLARE_PACKET_HANDLER (Client, PublicKey)
 DECLARE_PACKET_HANDLER (Client, Signature)

Variables

uint64_t s_curTick = 0
 Static variable keeping current tick.
const std::string TRACE_CLIENT = "Ed2kClient"
 Client trace mask.
const std::string TRACE_SECIDENT = "Ed2kClient::SecIdent"
const std::string TRACE_DEADSRC = "ED2KClient::DeadSource"
const std::string TRACE_SRCEXCH = "ED2KClient::SourceExchange"
ED2KUDPSockets_clientUdpSocket = 0
 UDP Socket for performing Client <-> Client UDP communication.

Detailed Description

Implementation of clients-related classes.

Definition in file clients.cpp.


Enumeration Type Documentation

enum Ed2k_ClientConstants
 

Here's a collection of things that can be used to tweak the ed2k inter-client communication procedures.

Don't change these unless you know what you'r doing. Incorrect values here can seriously affect the modules' networking performance.

Enumeration values:
SOURCE_REASKTIME  Time between source queue ranking reasks.

Ed2K netiquette says that you shouldn't do reasks more often than once per 30 minutes. Major clients drop queued clients from uploadqueue when no reask has been done during 1 hour. UDP reasks should be used when possible, falling back to TCP only if neccesery.

UDP_TIMEOUT  UDP reask timeout.

How long to wait for response after sending UDP ReaskFilePing. If two UDP reasks fail, we attempt TCP reask, if that also fails, drop the client as dead.

SOCKET_TIMEOUT  Specifies the TCP stream socket timeout; when there's no activity in the socket for this amount of time, the socket connection is dropped.

CALLBACK_TIMEOUT  Specifices LowID callback request timeout; if the called client doesn't respond within this timeframe, the client is considered dead.

lugdunum servers can delay LowId callbacks up to 12 seconds internally, in order to group several callback requests, so values lower than 15 seconds are not recommended.

CONNECT_TIMEOUT  Specifies the TCP connection attempt timeout.

Definition at line 50 of file clients.cpp.


Function Documentation

IMPLEMENT_EVENT_TABLE Client  ,
Client ,
ClientEvent 
 

DECLARE_PACKET_HANDLER Client  ,
Hello 
 

DECLARE_PACKET_HANDLER Client  ,
MuleInfo 
 

DECLARE_PACKET_HANDLER Client  ,
ReqFile 
 

DECLARE_PACKET_HANDLER Client  ,
SetReqFileId 
 

DECLARE_PACKET_HANDLER Client  ,
ReqHashSet 
 

DECLARE_PACKET_HANDLER Client  ,
StartUploadReq 
 

DECLARE_PACKET_HANDLER Client  ,
ReqChunks 
 

DECLARE_PACKET_HANDLER Client  ,
CancelTransfer 
 

DECLARE_PACKET_HANDLER Client  ,
FileName 
 

DECLARE_PACKET_HANDLER Client  ,
FileDesc 
 

DECLARE_PACKET_HANDLER Client  ,
FileStatus 
 

DECLARE_PACKET_HANDLER Client  ,
NoFile 
 

DECLARE_PACKET_HANDLER Client  ,
HashSet 
 

DECLARE_PACKET_HANDLER Client  ,
AcceptUploadReq 
 

DECLARE_PACKET_HANDLER Client  ,
QueueRanking 
 

DECLARE_PACKET_HANDLER Client  ,
MuleQueueRank 
 

DECLARE_PACKET_HANDLER Client  ,
DataChunk 
 

DECLARE_PACKET_HANDLER Client  ,
PackedChunk 
 

DECLARE_PACKET_HANDLER Client  ,
SourceExchReq 
 

DECLARE_PACKET_HANDLER Client  ,
AnswerSources 
 

DECLARE_PACKET_HANDLER Client  ,
Message 
 

DECLARE_PACKET_HANDLER Client  ,
ChangeId 
 

DECLARE_PACKET_HANDLER Client  ,
SecIdentState 
 

DECLARE_PACKET_HANDLER Client  ,
PublicKey 
 

DECLARE_PACKET_HANDLER Client  ,
Signature 
 


Variable Documentation

uint64_t s_curTick = 0
 

Static variable keeping current tick.

This is updated before time-calcuation operations to reduce getTick() calls during calculations.

Definition at line 42 of file clients.cpp.

Referenced by Client::getScore().

const std::string TRACE_CLIENT = "Ed2kClient"
 

Client trace mask.

Definition at line 91 of file clients.cpp.

const std::string TRACE_SECIDENT = "Ed2kClient::SecIdent"
 

Definition at line 92 of file clients.cpp.

const std::string TRACE_DEADSRC = "ED2KClient::DeadSource"
 

Definition at line 93 of file clients.cpp.

const std::string TRACE_SRCEXCH = "ED2KClient::SourceExchange"
 

Definition at line 94 of file clients.cpp.

ED2KUDPSocket* s_clientUdpSocket = 0
 

UDP Socket for performing Client <-> Client UDP communication.

Definition at line 97 of file clients.cpp.

Referenced by Client::getUdpSocket(), Client::onPacket(), and Client::reaskForDownload().

boost::signal<void (Client*, uint32_t) Detail::changeId)
 

Emitted when a client changes it's ID.

Parameters:
Client* Client that changed it's ID
uint32_t The new ID of the client

Definition at line 101 of file clients.cpp.

Referenced by Client::onPacket(), and Client::storeInfo().

boost::signal< bool(const Hash< ED2KHash > &, IPV4Address, IPV4Address, bool) > Detail::foundSource
 

Emitted when a new source is discovered by a client.

Parameters:
Hash<ED2KHash>& Hash of the file the source offers
IPV4Address Source IP/port
IPV4Address Server IP/port where the source is
bool If true, attempt to connect to the client now
Returns:
True if the source was added, false otherwise

Definition at line 104 of file clients.cpp.

Referenced by ServerList::handleGlobSources(), ServerList::onPacket(), and Client::onPacket().

boost::signal< void(IPV4Address)> Detail::foundServer
 

Emitted when a new server is discovered.

Parameters:
IPV4Address The server's IP/port

Definition at line 105 of file clients.cpp.

Referenced by Client::onPacket().