]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/connection.h
Textureable sun and moon.
[dragonfireclient.git] / src / connection.h
index e43d93fb30a7e1cd08365448c5c9bede903c5fa1..43fd2fb88e8b6735a4f46d53dbbfe6e063bee630 100644 (file)
@@ -71,14 +71,6 @@ class ConnectionBindFailed : public BaseException
        {}
 };
 
-/*class ThrottlingException : public BaseException
-{
-public:
-       ThrottlingException(const char *s):
-               BaseException(s)
-       {}
-};*/
-
 class InvalidIncomingDataException : public BaseException
 {
 public:
@@ -347,13 +339,11 @@ class ReliablePacketBuffer
        RPBSearchResult findPacket(u16 seqnum);
 
        std::list<BufferedPacket> m_list;
-       u16 m_list_size;
+       u32 m_list_size;
 
        u16 m_oldest_non_answered_ack;
 
        JMutex m_list_mutex;
-
-       unsigned int writeptr;
 };
 
 /*
@@ -406,7 +396,6 @@ enum ConnectionCommandType{
        CONNCMD_DISCONNECT_PEER,
        CONNCMD_SEND,
        CONNCMD_SEND_TO_ALL,
-       CONNCMD_DELETE_PEER,
        CONCMD_ACK,
        CONCMD_CREATE_PEER,
        CONCMD_DISABLE_LEGACY
@@ -415,7 +404,6 @@ enum ConnectionCommandType{
 struct ConnectionCommand
 {
        enum ConnectionCommandType type;
-       u16 port;
        Address address;
        u16 peer_id;
        u8 channelnum;
@@ -425,10 +413,10 @@ struct ConnectionCommand
 
        ConnectionCommand(): type(CONNCMD_NONE), peer_id(PEER_ID_INEXISTENT), reliable(false), raw(false) {}
 
-       void serve(u16 port_)
+       void serve(Address address_)
        {
                type = CONNCMD_SERVE;
-               port = port_;
+               address = address_;
        }
        void connect(Address address_)
        {
@@ -460,11 +448,6 @@ struct ConnectionCommand
                data = data_;
                reliable = reliable_;
        }
-       void deletePeer(u16 peer_id_)
-       {
-               type = CONNCMD_DELETE_PEER;
-               peer_id = peer_id_;
-       }
 
        void ack(u16 peer_id_, u8 channelnum_, SharedBuffer<u8> data_)
        {
@@ -580,16 +563,29 @@ class Channel
 
 class Peer;
 
+enum PeerChangeType
+{
+       PEER_ADDED,
+       PEER_REMOVED
+};
+struct PeerChange
+{
+       PeerChangeType type;
+       u16 peer_id;
+       bool timeout;
+};
+
 class PeerHandler
 {
 public:
+
        PeerHandler()
        {
        }
        virtual ~PeerHandler()
        {
        }
-       
+
        /*
                This is called after the Peer has been inserted into the
                Connection's peer container.
@@ -771,7 +767,7 @@ class UDPPeer : public Peer
        friend class ConnectionSendThread;
 
        UDPPeer(u16 a_id, Address a_address, Connection* connection);
-       virtual ~UDPPeer();
+       virtual ~UDPPeer() {};
 
        void PutReliableSendCommand(ConnectionCommand &c,
                                                        unsigned int max_packet_size);
@@ -781,8 +777,7 @@ class UDPPeer : public Peer
 
        bool getAddress(MTProtocols type, Address& toset);
 
-       void setNonLegacyPeer()
-       { m_legacy_peer = false; }
+       void setNonLegacyPeer();
 
        bool getLegacyPeer()
        { return m_legacy_peer; }
@@ -793,6 +788,8 @@ class UDPPeer : public Peer
        SharedBuffer<u8> addSpiltPacket(u8 channel,
                                                                        BufferedPacket toadd,
                                                                        bool reliable);
+
+
 protected:
        /*
                Calculates avg_rtt and resend_timeout.
@@ -813,6 +810,7 @@ class UDPPeer : public Peer
        bool Ping(float dtime,SharedBuffer<u8>& data);
 
        Channel channels[CHANNEL_COUNT];
+       bool m_pending_disconnect;
 private:
        // This is changed dynamically
        float resend_timeout;
@@ -911,7 +909,7 @@ class ConnectionSendThread : public JThread {
 
        void processReliableCommand (ConnectionCommand &c);
        void processNonReliableCommand (ConnectionCommand &c);
-       void serve          (u16 port);
+       void serve          (Address bind_address);
        void connect        (Address address);
        void disconnect     ();
        void disconnect_peer(u16 peer_id);
@@ -975,7 +973,6 @@ class ConnectionReceiveThread : public JThread {
 
 
        Connection*           m_connection;
-       unsigned int          m_max_packet_size;
 };
 
 class Connection
@@ -995,20 +992,19 @@ class Connection
        void putCommand(ConnectionCommand &c);
        
        void SetTimeoutMs(int timeout){ m_bc_receive_timeout = timeout; }
-       void Serve(unsigned short port);
+       void Serve(Address bind_addr);
        void Connect(Address address);
        bool Connected();
        void Disconnect();
        u32 Receive(u16 &peer_id, SharedBuffer<u8> &data);
        void SendToAll(u8 channelnum, SharedBuffer<u8> data, bool reliable);
        void Send(u16 peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable);
-       void RunTimeouts(float dtime); // dummy
        u16 GetPeerID(){ return m_peer_id; }
        Address GetPeerAddress(u16 peer_id);
-       float GetPeerAvgRTT(u16 peer_id);
-       void DeletePeer(u16 peer_id);
+       float getPeerStat(u16 peer_id, rtt_stat_type type);
        const u32 GetProtocolID() const { return m_protocol_id; };
        const std::string getDesc();
+       void DisconnectPeer(u16 peer_id);
 
 protected:
        PeerHelper getPeer(u16 peer_id);
@@ -1033,6 +1029,8 @@ class Connection
 
        void putEvent(ConnectionEvent &e);
 
+       void TriggerSend()
+               { m_sendThread.Trigger(); }
 private:
        std::list<Peer*> getPeers();
 
@@ -1054,6 +1052,8 @@ class Connection
        int m_bc_receive_timeout;
 
        bool m_shutting_down;
+
+       u16 m_next_remote_peer_id;
 };
 
 } // namespace