Shadowrun: Awakened 29 September 2011 - Build 871
RakPeer.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 // TODO - RakNet 4 - Add network simulator
00009 // TODO - RakNet 4 - Enable disabling flow control per connections
00010 
00011 #ifndef __RAK_PEER_H
00012 #define __RAK_PEER_H
00013 
00014 #include "ReliabilityLayer.h"
00015 #include "RakPeerInterface.h"
00016 #include "BitStream.h"
00017 #include "SingleProducerConsumer.h"
00018 #include "SimpleMutex.h"
00019 #include "DS_OrderedList.h"
00020 #include "Export.h"
00021 #include "RakString.h"
00022 #include "RakThread.h"
00023 #include "RakNetSocket.h"
00024 #include "RakNetSmartPtr.h"
00025 #include "DS_ThreadsafeAllocatingQueue.h"
00026 #include "SignaledEvent.h"
00027 #include "NativeFeatureIncludes.h"
00028 #include "SecureHandshake.h"
00029 #include "LocklessTypes.h"
00030 
00031 namespace RakNet {
00033 class HuffmanEncodingTree;
00034 class PluginInterface2;
00035 
00036 // Sucks but this struct has to be outside the class.  Inside and DevCPP won't let you refer to the struct as RakPeer::RemoteSystemIndex while GCC
00037 // forces you to do RakPeer::RemoteSystemIndex
00038 struct RemoteSystemIndex{unsigned index; RemoteSystemIndex *next;};
00039 //int RAK_DLL_EXPORT SystemAddressAndIndexComp( const SystemAddress &key, const RemoteSystemIndex &data ); // GCC requires RakPeer::RemoteSystemIndex or it won't compile
00040 
00048 class RAK_DLL_EXPORT RakPeer : public RakPeerInterface
00049 {
00050 public:
00052     RakPeer();
00053 
00055     virtual ~RakPeer();
00056 
00057     // --------------------------------------------------------------------------------------------Major Low Level Functions - Functions needed by most users--------------------------------------------------------------------------------------------
00069     StartupResult Startup( unsigned short maxConnections, SocketDescriptor *socketDescriptors, unsigned socketDescriptorCount, int threadPriority=-99999 );
00070 
00080     bool InitializeSecurity( const char *publicKey, const char *privateKey, bool bRequireClientKey = false );
00081 
00084     void DisableSecurity( void );
00085 
00091     void AddToSecurityExceptionList(const char *ip);
00092 
00095     void RemoveFromSecurityExceptionList(const char *ip);
00096 
00100     bool IsInSecurityExceptionList(const char *ip);
00101 
00109     void SetMaximumIncomingConnections( unsigned short numberAllowed );
00110 
00113     unsigned short GetMaximumIncomingConnections( void ) const;
00114 
00117     unsigned short NumberOfConnections(void) const;
00118 
00125     void SetIncomingPassword( const char* passwordData, int passwordDataLength );
00126 
00130     void GetIncomingPassword( char* passwordData, int *passwordDataLength  );
00131 
00153     ConnectionAttemptResult Connect( const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey=0, unsigned connectionSocketIndex=0, unsigned sendConnectionAttemptCount=6, unsigned timeBetweenSendConnectionAttemptsMS=1000, RakNet::TimeMS timeoutTime=0 );
00154 
00166     virtual ConnectionAttemptResult ConnectWithSocket(const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, RakNetSmartPtr<RakNetSocket> socket, PublicKey *publicKey=0, unsigned sendConnectionAttemptCount=6, unsigned timeBetweenSendConnectionAttemptsMS=1000, RakNet::TimeMS timeoutTime=0);
00167 
00168     /* /// \brief Connect to the specified network ID (Platform specific console function)
00173     //bool Console2LobbyConnect( void *networkServiceId, const char *passwordData, int passwordDataLength );*/  
00174 
00180     void Shutdown( unsigned int blockDuration, unsigned char orderingChannel=0, PacketPriority disconnectionNotificationPriority=LOW_PRIORITY );
00181 
00184     bool IsActive( void ) const;
00185 
00189     bool GetConnectionList( SystemAddress *remoteSystems, unsigned short *numberOfSystems ) const;
00190 
00194     virtual uint32_t GetNextSendReceipt(void);
00195 
00199     virtual uint32_t IncrementNextSendReceipt(void);
00200 
00213     uint32_t Send( const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0 );
00214 
00221     void SendLoopback( const char *data, const int length );
00222 
00235     uint32_t Send( const RakNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0 );
00236 
00257     uint32_t SendList( const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0 );
00258 
00265     Packet* Receive( void );
00266 
00269     void DeallocatePacket( Packet *packet );
00270 
00273     unsigned short GetMaximumNumberOfPeers( void ) const;
00274 
00275     // -------------------------------------------------------------------------------------------- Connection Management Functions--------------------------------------------------------------------------------------------
00282     void CloseConnection( const AddressOrGUID target, bool sendDisconnectionNotification, unsigned char orderingChannel=0, PacketPriority disconnectionNotificationPriority=LOW_PRIORITY );
00283 
00287     void CancelConnectionAttempt( const SystemAddress target );
00292     ConnectionState GetConnectionState(const AddressOrGUID systemIdentifier);
00293 
00299     int GetIndexFromSystemAddress( const SystemAddress systemAddress ) const;
00300 
00306     SystemAddress GetSystemAddressFromIndex( int index );
00307 
00311     RakNetGUID GetGUIDFromIndex( int index );
00312 
00317     void GetSystemList(DataStructures::List<SystemAddress> &addresses, DataStructures::List<RakNetGUID> &guids) const;
00318 
00323     void AddToBanList( const char *IP, RakNet::TimeMS milliseconds=0 );
00324 
00327     void RemoveFromBanList( const char *IP );
00328 
00330     void ClearBanList( void );
00331 
00335     bool IsBanned( const char *IP );
00336 
00340     void SetLimitIPConnectionFrequency(bool b);
00341     
00342     // --------------------------------------------------------------------------------------------Pinging Functions - Functions dealing with the automatic ping mechanism--------------------------------------------------------------------------------------------
00346     void Ping( const SystemAddress target );
00347 
00356     bool Ping( const char* host, unsigned short remotePort, bool onlyReplyOnAcceptingConnections, unsigned connectionSocketIndex=0 );
00357 
00361     int GetAveragePing( const AddressOrGUID systemIdentifier );
00362 
00366     int GetLastPing( const AddressOrGUID systemIdentifier ) const;
00367 
00371     int GetLowestPing( const AddressOrGUID systemIdentifier ) const;
00372 
00377     void SetOccasionalPing( bool doPing );
00378     
00379     // --------------------------------------------------------------------------------------------Static Data Functions - Functions dealing with API defined synchronized memory--------------------------------------------------------------------------------------------
00385     void SetOfflinePingResponse( const char *data, const unsigned int length );
00386 
00391     void GetOfflinePingResponse( char **data, unsigned int *length );
00392     
00393     //--------------------------------------------------------------------------------------------Network Functions - Functions dealing with the network in general--------------------------------------------------------------------------------------------
00399     SystemAddress GetInternalID( const SystemAddress systemAddress=UNASSIGNED_SYSTEM_ADDRESS, const int index=0 ) const;
00400 
00403     SystemAddress GetExternalID( const SystemAddress target ) const;
00404 
00406     const RakNetGUID GetMyGUID(void);
00407 
00409     SystemAddress GetMyBoundAddress(const int socketIndex=0);
00410 
00417     const RakNetGUID& GetGuidFromSystemAddress( const SystemAddress input ) const;
00418 
00424     SystemAddress GetSystemAddressFromGuid( const RakNetGUID input ) const;
00425 
00430     bool GetClientPublicKeyFromSystemAddress( const SystemAddress input, char *client_public_key ) const;
00431 
00433 
00439     void SetTimeoutTime( RakNet::TimeMS timeMS, const SystemAddress target );
00440     
00444     RakNet::TimeMS GetTimeoutTime( const SystemAddress target );
00445 
00449     int GetMTUSize( const SystemAddress target ) const;
00450 
00453     unsigned GetNumberOfAddresses( void );
00454 
00458     const char* GetLocalIP( unsigned int index );
00459 
00464     bool IsLocalIP( const char *ip );
00465 
00469     void AllowConnectionResponseIPMigration( bool allow );
00470 
00480     bool AdvertiseSystem( const char *host, unsigned short remotePort, const char *data, int dataLength, unsigned connectionSocketIndex=0 );
00481 
00487     void SetSplitMessageProgressInterval(int interval);
00488 
00491     int GetSplitMessageProgressInterval(void) const;
00492 
00497     void SetUnreliableTimeout(RakNet::TimeMS timeoutMS);
00498 
00506     void SendTTL( const char* host, unsigned short remotePort, int ttl, unsigned connectionSocketIndex=0 );
00507 
00508     // -------------------------------------------------------------------------------------------- Plugin Functions--------------------------------------------------------------------------------------------
00511     void AttachPlugin( PluginInterface2 *plugin );
00512 
00516     void DetachPlugin( PluginInterface2 *messageHandler );
00517 
00518     // --------------------------------------------------------------------------------------------Miscellaneous Functions--------------------------------------------------------------------------------------------
00523     void PushBackPacket( Packet *packet, bool pushAtHead );
00524 
00529     void ChangeSystemAddress(RakNetGUID guid, const SystemAddress &systemAddress);
00530 
00535     Packet* AllocatePacket(unsigned dataSize);
00536 
00542     virtual RakNetSmartPtr<RakNetSocket> GetSocket( const SystemAddress target );
00543 
00547     virtual void GetSockets( DataStructures::List<RakNetSmartPtr<RakNetSocket> > &sockets );
00548     virtual void ReleaseSockets( DataStructures::List<RakNetSmartPtr<RakNetSocket> > &sockets );
00549 
00551     virtual void WriteOutOfBandHeader(RakNet::BitStream *bitStream);
00552 
00556     virtual void SetUserUpdateThread(void (*_userUpdateThreadPtr)(RakPeerInterface *, void *), void *_userUpdateThreadData);
00557 
00558     // --------------------------------------------------------------------------------------------Network Simulator Functions--------------------------------------------------------------------------------------------
00567     virtual void ApplyNetworkSimulator( float packetloss, unsigned short minExtraPing, unsigned short extraPingVariance);
00568 
00573     virtual void SetPerConnectionOutgoingBandwidthLimit( unsigned maxBitsPerSecond );
00574 
00577     virtual bool IsNetworkSimulatorActive( void );
00578 
00579     // --------------------------------------------------------------------------------------------Statistical Functions - Functions dealing with API performance--------------------------------------------------------------------------------------------
00580 
00587     RakNetStatistics * GetStatistics( const SystemAddress systemAddress, RakNetStatistics *rns=0 );
00590     bool GetStatistics( const int index, RakNetStatistics *rns );
00591 
00593     virtual unsigned int GetReceiveBufferSize(void);
00594 
00595     // --------------------------------------------------------------------------------------------EVERYTHING AFTER THIS COMMENT IS FOR INTERNAL USE ONLY--------------------------------------------------------------------------------------------
00596 
00598     bool SendOutOfBand(const char *host, unsigned short remotePort, const char *data, BitSize_t dataLength, unsigned connectionSocketIndex=0 );
00599 
00600     // static Packet *AllocPacket(unsigned dataSize, const char *file, unsigned int line);
00601 
00604     struct PingAndClockDifferential
00605     {
00606         unsigned short pingTime;
00607         RakNet::Time clockDifferential;
00608     };
00609 
00612     struct RemoteSystemStruct
00613     {
00614         bool isActive; // Is this structure in use?
00615         SystemAddress systemAddress;  
00616         SystemAddress myExternalSystemAddress;  
00617         SystemAddress theirInternalSystemAddress[MAXIMUM_NUMBER_OF_INTERNAL_IDS];  
00618         ReliabilityLayer reliabilityLayer;  
00619         bool weInitiatedTheConnection; 
00620         PingAndClockDifferential pingAndClockDifferential[ PING_TIMES_ARRAY_SIZE ];  
00621         RakNet::Time pingAndClockDifferentialWriteIndex;  
00622         unsigned short lowestPing; 
00623         RakNet::Time nextPingTime;  
00624         RakNet::Time lastReliableSend; 
00625         RakNet::Time connectionTime; 
00626 //      int connectionSocketIndex; // index into connectionSockets to send back on.
00627         RakNetGUID guid;
00628         int MTUSize;
00629         // Reference counted socket to send back on
00630         RakNetSmartPtr<RakNetSocket> rakNetSocket;
00631         SystemIndex remoteSystemIndex;
00632 
00633 #if LIBCAT_SECURITY==1
00634         // Cached answer used internally by RakPeer to prevent DoS attacks based on the connexion handshake
00635         char answer[cat::EasyHandshake::ANSWER_BYTES];
00636 
00637         // If the server has bRequireClientKey = true, then this is set to the validated public key of the connected client
00638         // Valid after connectMode reaches HANDLING_CONNECTION_REQUEST
00639         char client_public_key[cat::EasyHandshake::PUBLIC_KEY_BYTES];
00640 #endif
00641 
00642         enum ConnectMode {NO_ACTION, DISCONNECT_ASAP, DISCONNECT_ASAP_SILENTLY, DISCONNECT_ON_NO_ACK, REQUESTED_CONNECTION, HANDLING_CONNECTION_REQUEST, UNVERIFIED_SENDER, CONNECTED} connectMode;
00643     };
00644 
00645 protected:
00646 
00647     friend RAK_THREAD_DECLARATION(UpdateNetworkLoop);
00648     friend RAK_THREAD_DECLARATION(RecvFromLoop);
00649     friend RAK_THREAD_DECLARATION(UDTConnect);
00650 
00651     friend bool ProcessOfflineNetworkPacket( SystemAddress systemAddress, const char *data, const int length, RakPeer *rakPeer, RakNetSmartPtr<RakNetSocket> rakNetSocket, bool *isOfflineMessage, RakNet::TimeUS timeRead );
00652     friend void ProcessNetworkPacket( const SystemAddress systemAddress, const char *data, const int length, RakPeer *rakPeer, RakNet::TimeUS timeRead );
00653     friend void ProcessNetworkPacket( const SystemAddress systemAddress, const char *data, const int length, RakPeer *rakPeer, RakNetSmartPtr<RakNetSocket> rakNetSocket, RakNet::TimeUS timeRead );
00654 
00655     int GetIndexFromSystemAddress( const SystemAddress systemAddress, bool calledFromNetworkThread ) const;
00656     int GetIndexFromGuid( const RakNetGUID guid );
00657 
00658     //void RemoveFromRequestedConnectionsList( const SystemAddress systemAddress );
00659     // Two versions needed because some buggy compilers strip the last parameter if unused, and crashes
00660     ConnectionAttemptResult SendConnectionRequest( const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey, unsigned connectionSocketIndex, unsigned int extraData, unsigned sendConnectionAttemptCount, unsigned timeBetweenSendConnectionAttemptsMS, RakNet::TimeMS timeoutTime, RakNetSmartPtr<RakNetSocket> socket );
00661     ConnectionAttemptResult SendConnectionRequest( const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey, unsigned connectionSocketIndex, unsigned int extraData, unsigned sendConnectionAttemptCount, unsigned timeBetweenSendConnectionAttemptsMS, RakNet::TimeMS timeoutTime );
00665     RemoteSystemStruct *GetRemoteSystemFromSystemAddress( const SystemAddress systemAddress, bool calledFromNetworkThread, bool onlyActive ) const;
00666     RakPeer::RemoteSystemStruct *GetRemoteSystem( const AddressOrGUID systemIdentifier, bool calledFromNetworkThread, bool onlyActive ) const;
00667     void ValidateRemoteSystemLookup(void) const;
00668     RemoteSystemStruct *GetRemoteSystemFromGUID( const RakNetGUID guid, bool onlyActive ) const;
00670     void ParseConnectionRequestPacket( RakPeer::RemoteSystemStruct *remoteSystem, const SystemAddress &systemAddress, const char *data, int byteSize);
00671     void OnConnectionRequest( RakPeer::RemoteSystemStruct *remoteSystem, RakNet::Time incomingTimestamp );
00673     void NotifyAndFlagForShutdown( const SystemAddress systemAddress, bool performImmediate, unsigned char orderingChannel, PacketPriority disconnectionNotificationPriority );
00675     unsigned short GetNumberOfRemoteInitiatedConnections( void ) const;
00684     RemoteSystemStruct * AssignSystemAddressToRemoteSystemList( const SystemAddress systemAddress, RemoteSystemStruct::ConnectMode connectionMode, RakNetSmartPtr<RakNetSocket> incomingRakNetSocket, bool *thisIPConnectedRecently, SystemAddress bindingAddress, int incomingMTU, RakNetGUID guid, bool useSecurity );
00688     void ShiftIncomingTimestamp( unsigned char *data, const SystemAddress &systemAddress ) const;
00692     RakNet::Time GetBestClockDifferential( const SystemAddress systemAddress ) const;
00693 
00694     bool IsLoopbackAddress(const AddressOrGUID &systemIdentifier, bool matchPort) const;
00695     SystemAddress GetLoopbackAddress(void) const;
00696 
00698     volatile bool endThreads;
00700     volatile bool isMainLoopThreadActive;
00701     
00702     RakNet::LocklessUint32_t isRecvFromLoopThreadActive;
00703 
00704 
00705     bool occasionalPing;  
00706 
00707     unsigned short maximumNumberOfPeers;
00708     //05/02/06 Just using maximumNumberOfPeers instead
00710     //unsigned short remoteSystemListSize;
00712     unsigned short maximumIncomingConnections;
00713     RakNet::BitStream offlinePingResponse;
00715     // SystemAddress mySystemAddress[MAXIMUM_NUMBER_OF_INTERNAL_IDS];
00716     char incomingPassword[256];
00717     unsigned char incomingPasswordLength;
00718 
00723     RemoteSystemStruct* remoteSystemList;
00727     RemoteSystemStruct** activeSystemList;
00728     unsigned int activeSystemListSize;
00729 
00730     // Use a hash, with binaryAddress plus port mod length as the index
00731     RemoteSystemIndex **remoteSystemLookup;
00732     unsigned int RemoteSystemLookupHashIndex(const SystemAddress &sa) const;
00733     void ReferenceRemoteSystem(const SystemAddress &sa, unsigned int remoteSystemListIndex);
00734     void DereferenceRemoteSystem(const SystemAddress &sa);
00735     RemoteSystemStruct* GetRemoteSystem(const SystemAddress &sa) const;
00736     unsigned int GetRemoteSystemIndex(const SystemAddress &sa) const;
00737     void ClearRemoteSystemLookup(void);
00738     DataStructures::MemoryPool<RemoteSystemIndex> remoteSystemIndexPool;
00739 
00740     void AddToActiveSystemList(unsigned int remoteSystemListIndex);
00741     void RemoveFromActiveSystemList(const SystemAddress &sa);
00742 
00743 //  unsigned int LookupIndexUsingHashIndex(const SystemAddress &sa) const;
00744 //  unsigned int RemoteSystemListIndexUsingHashIndex(const SystemAddress &sa) const;
00745 //  unsigned int FirstFreeRemoteSystemLookupIndex(const SystemAddress &sa) const;
00746     
00747     enum
00748     {
00749         // Only put these mutexes in user thread functions!
00750         requestedConnectionList_Mutex,
00751         offlinePingResponse_Mutex,
00752         NUMBER_OF_RAKPEER_MUTEXES
00753     };
00754     SimpleMutex rakPeerMutexes[ NUMBER_OF_RAKPEER_MUTEXES ];
00756 
00757     bool updateCycleIsRunning;
00759 
00760     //DataStructures::Queue<RequestedConnectionStruct*> requestedConnectionsList;
00762 
00763     unsigned int bytesSentPerSecond, bytesReceivedPerSecond;
00764     // bool isSocketLayerBlocking;
00765     // bool continualPing,isRecvfromThreadActive,isMainLoopThreadActive, endThreads, isSocketLayerBlocking;
00766     unsigned int validationInteger;
00767     SimpleMutex incomingQueueMutex, banListMutex; //,synchronizedMemoryQueueMutex, automaticVariableSynchronizationMutex;
00768     //DataStructures::Queue<Packet *> incomingpacketSingleProducerConsumer; //, synchronizedMemorypacketSingleProducerConsumer;
00769     // BitStream enumerationData;
00770 
00771     struct BanStruct
00772     {
00773         char *IP;
00774         RakNet::TimeMS timeout; // 0 for none
00775     };
00776 
00777     struct RequestedConnectionStruct
00778     {
00779         SystemAddress systemAddress;
00780         RakNet::Time nextRequestTime;
00781         unsigned char requestsMade;
00782         char *data;
00783         unsigned short dataLength;
00784         char outgoingPassword[256];
00785         unsigned char outgoingPasswordLength;
00786         unsigned socketIndex;
00787         unsigned int extraData;
00788         unsigned sendConnectionAttemptCount;
00789         unsigned timeBetweenSendConnectionAttemptsMS;
00790         RakNet::TimeMS timeoutTime;
00791         PublicKeyMode publicKeyMode;
00792         RakNetSmartPtr<RakNetSocket> socket;
00793         enum {CONNECT=1, /*PING=2, PING_OPEN_CONNECTIONS=4,*/ /*ADVERTISE_SYSTEM=2*/} actionToTake;
00794 
00795 #if LIBCAT_SECURITY==1
00796         char handshakeChallenge[cat::EasyHandshake::CHALLENGE_BYTES];
00797         cat::ClientEasyHandshake *client_handshake;
00798         char remote_public_key[cat::EasyHandshake::PUBLIC_KEY_BYTES];
00799 //      char remote_challenge[cat::EasyHandshake::CHALLENGE_BYTES];
00800     //  char random[16];
00801 #endif
00802     };
00803 #if LIBCAT_SECURITY==1
00804     bool GenerateConnectionRequestChallenge(RequestedConnectionStruct *rcs,PublicKey *publicKey);
00805 #endif
00806 
00807     //DataStructures::List<DataStructures::List<MemoryBlock>* > automaticVariableSynchronizationList;
00808     DataStructures::List<BanStruct*> banList;
00809     DataStructures::List<PluginInterface2*> messageHandlerList;
00810 
00811     DataStructures::Queue<RequestedConnectionStruct*> requestedConnectionQueue;
00812     SimpleMutex requestedConnectionQueueMutex;
00813 
00814     bool RunUpdateCycle( RakNet::TimeUS timeNS, RakNet::Time timeMS );
00815     // void RunMutexedUpdateCycle(void);
00816 
00817     struct BufferedCommandStruct
00818     {
00819         BitSize_t numberOfBitsToSend;
00820         PacketPriority priority;
00821         PacketReliability reliability;
00822         char orderingChannel;
00823         AddressOrGUID systemIdentifier;
00824         bool broadcast;
00825         RemoteSystemStruct::ConnectMode connectionMode;
00826         NetworkID networkID;
00827         bool blockingCommand; // Only used for RPC
00828         char *data;
00829         bool haveRakNetCloseSocket;
00830         unsigned connectionSocketIndex;
00831         unsigned short remotePortRakNetWasStartedOn_PS3;
00832         unsigned int extraSocketOptions;
00833         SOCKET socket;
00834         unsigned short port;
00835         uint32_t receipt;
00836         enum {BCS_SEND, BCS_CLOSE_CONNECTION, BCS_GET_SOCKET, BCS_CHANGE_SYSTEM_ADDRESS,/* BCS_USE_USER_SOCKET, BCS_REBIND_SOCKET_ADDRESS, BCS_RPC, BCS_RPC_SHIFT,*/ BCS_DO_NOTHING} command;
00837     };
00838 
00839     // Single producer single consumer queue using a linked list
00840     //BufferedCommandStruct* bufferedCommandReadIndex, bufferedCommandWriteIndex;
00841 
00842     DataStructures::ThreadsafeAllocatingQueue<BufferedCommandStruct> bufferedCommands;
00843 
00844 
00845     // Constructor not called!
00846     struct RecvFromStruct
00847     {
00848 
00849 
00850 
00851         char data[MAXIMUM_MTU_SIZE];
00852 
00853         int bytesRead;
00854         SystemAddress systemAddress;
00855         RakNet::TimeUS timeRead;
00856         SOCKET s;
00857         unsigned short remotePortRakNetWasStartedOn_PS3;
00858         unsigned int extraSocketOptions;
00859     };
00860 
00861 
00862     DataStructures::ThreadsafeAllocatingQueue<RecvFromStruct> bufferedPackets;
00863 
00864 
00865     struct SocketQueryOutput
00866     {
00867         SocketQueryOutput() {}
00868         ~SocketQueryOutput() {}
00869         DataStructures::List<RakNetSmartPtr<RakNetSocket> > sockets;
00870     };
00871 
00872     DataStructures::ThreadsafeAllocatingQueue<SocketQueryOutput> socketQueryOutput;
00873 
00874 
00875     bool AllowIncomingConnections(void) const;
00876 
00877     void PingInternal( const SystemAddress target, bool performImmediate, PacketReliability reliability );
00878     // This stores the user send calls to be handled by the update thread.  This way we don't have thread contention over systemAddresss
00879     void CloseConnectionInternal( const AddressOrGUID& systemIdentifier, bool sendDisconnectionNotification, bool performImmediate, unsigned char orderingChannel, PacketPriority disconnectionNotificationPriority );
00880     void SendBuffered( const char *data, BitSize_t numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, RemoteSystemStruct::ConnectMode connectionMode, uint32_t receipt );
00881     void SendBufferedList( const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, RemoteSystemStruct::ConnectMode connectionMode, uint32_t receipt );
00882     bool SendImmediate( char *data, BitSize_t numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, bool useCallerDataAllocation, RakNet::TimeUS currentTime, uint32_t receipt );
00883     //bool HandleBufferedRPC(BufferedCommandStruct *bcs, RakNet::TimeMS time);
00884     void ClearBufferedCommands(void);
00885     void ClearBufferedPackets(void);
00886     void ClearSocketQueryOutput(void);
00887     void ClearRequestedConnectionList(void);
00888     void AddPacketToProducer(RakNet::Packet *p);
00889     unsigned int GenerateSeedFromGuid(void);
00890     SimpleMutex securityExceptionMutex;
00891 
00892     //DataStructures::AVLBalancedBinarySearchTree<RPCNode> rpcTree;
00893     int defaultMTUSize;
00894     bool trackFrequencyTable;
00895 
00896     // Smart pointer so I can return the object to the user
00897     DataStructures::List<RakNetSmartPtr<RakNetSocket> > socketList;
00898     void DerefAllSockets(void);
00899     unsigned int GetRakNetSocketFromUserConnectionSocketIndex(unsigned int userIndex) const;
00900     // Used for RPC replies
00901     RakNet::BitStream *replyFromTargetBS;
00902     SystemAddress replyFromTargetPlayer;
00903     bool replyFromTargetBroadcast;
00904 
00905     RakNet::TimeMS defaultTimeoutTime;
00906 
00907     // Generate and store a unique GUID
00908     void GenerateGUID(void);
00909     unsigned int GetSystemIndexFromGuid( const RakNetGUID input ) const;
00910     RakNetGUID myGuid;
00911 
00912     unsigned maxOutgoingBPS;
00913 
00914     // Nobody would use the internet simulator in a final build.
00915 #ifdef _DEBUG
00916     double _packetloss;
00917     unsigned short _minExtraPing, _extraPingVariance;
00918 #endif
00919     
00921     //unsigned int lastUserUpdateCycle;
00923     bool allowConnectionResponseIPMigration;
00924 
00925     SystemAddress firstExternalID;
00926     int splitMessageProgressInterval;
00927     RakNet::TimeMS unreliableTimeout;
00928 
00929     // Systems in this list will not go through the secure connection process, even when secure connections are turned on. Wildcards are accepted.
00930     DataStructures::List<RakNet::RakString> securityExceptionList;
00931 
00932     SystemAddress ipList[ MAXIMUM_NUMBER_OF_INTERNAL_IDS ];
00933 
00934     bool allowInternalRouting;
00935 
00936     void (*userUpdateThreadPtr)(RakPeerInterface *, void *);
00937     void *userUpdateThreadData;
00938 
00939 
00940     SignaledEvent quitAndDataEvents;
00941     bool limitConnectionFrequencyFromTheSameIP;
00942 
00943     SimpleMutex packetAllocationPoolMutex;
00944     DataStructures::MemoryPool<Packet> packetAllocationPool;
00945 
00946     SimpleMutex packetReturnMutex;
00947     DataStructures::Queue<Packet*> packetReturnQueue;
00948     Packet *AllocPacket(unsigned dataSize, const char *file, unsigned int line);
00949     Packet *AllocPacket(unsigned dataSize, unsigned char *data, const char *file, unsigned int line);
00950 
00954     SimpleMutex sendReceiptSerialMutex;
00955     uint32_t sendReceiptSerial;
00956     void ResetSendReceipt(void);
00957     void OnConnectedPong(RakNet::Time sendPingTime, RakNet::Time sendPongTime, RemoteSystemStruct *remoteSystem);
00958 
00959 #if LIBCAT_SECURITY==1
00960     // Encryption and security
00961     bool _using_security, _require_client_public_key;
00962     char my_public_key[cat::EasyHandshake::PUBLIC_KEY_BYTES];
00963     cat::ServerEasyHandshake *_server_handshake;
00964     cat::CookieJar *_cookie_jar;
00965     bool InitializeClientSecurity(RequestedConnectionStruct *rcs, const char *public_key);
00966 #endif
00967 
00968 
00969 
00970 
00971 
00972 } 
00973 // #if defined(SN_TARGET_PSP2)
00974 // __attribute__((aligned(8)))
00975 // #endif
00976 ;
00977 
00978 } // namespace RakNet
00979 
00980 #endif

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net