add .gitignore
[swift-upb.git] / swift.h
diff --git a/swift.h b/swift.h
index be996c7..5472a94 100644 (file)
--- a/swift.h
+++ b/swift.h
@@ -123,6 +123,7 @@ namespace swift {
     class PiecePicker;
     class CongestionController;
     class PeerSelector;
+    typedef void (*ProgressCallback) (int transfer, bin64_t bin);
 
 
     /** A class representing single file transfer. */
@@ -186,6 +187,11 @@ namespace swift {
 
         tint            init_time_;
 
+        #define SWFT_MAX_TRANSFER_CB 8
+        ProgressCallback callbacks[SWFT_MAX_TRANSFER_CB];
+        uint8_t         cb_agg[SWFT_MAX_TRANSFER_CB];
+        int             cb_installed;
+
     public:
         void            OnDataIn (bin64_t pos);
         void            OnPexIn (const Address& addr);
@@ -197,6 +203,9 @@ namespace swift {
         friend uint64_t  SeqComplete (int fdes);
         friend int     Open (const char* filename, const Sha1Hash& hash) ;
         friend void    Close (int fd) ;
+        friend void AddProgressCallback (int transfer,ProgressCallback cb,uint8_t agg);
+        friend void RemoveProgressCallback (int transfer,ProgressCallback cb);
+        friend void ExternallyRetrieved (int transfer,bin64_t piece);
     };
 
 
@@ -213,6 +222,7 @@ namespace swift {
          *  @param  expires     (not used currently) when to consider request expired
          *  @return             the bin number to request */
         virtual bin64_t Pick (binmap_t& offered, uint64_t max_width, tint expires) = 0;
+        virtual void LimitRange (bin64_t range) = 0;
         virtual ~PiecePicker() {}
     };
 
@@ -239,7 +249,7 @@ namespace swift {
         Normally, API users do not deal with this class. */
     class Channel {
     public:
-        Channel    (FileTransfer* file, int socket=-1, Address peer=Address());
+        Channel    (FileTransfer* file, int socket=INVALID_SOCKET, Address peer=Address());
         ~Channel();
 
         typedef enum {
@@ -253,8 +263,7 @@ namespace swift {
 
         static const char* SEND_CONTROL_MODES[];
 
-        static Channel*
-                    RecvDatagram (int socket);
+        static void RecvDatagram (SOCKET socket);
         static void Loop (tint till);
 
         void        Recv (Datagram& dgram);
@@ -317,7 +326,6 @@ namespace swift {
             return i<channels.size()?channels[i]:NULL;
         }
         static void CloseTransfer (FileTransfer* trans);
-        static SOCKET default_socket() { return sockets[0]; }
 
     protected:
         /** Channel id: index in the channel array. */
@@ -397,8 +405,6 @@ namespace swift {
 
         static PeerSelector* peer_selector;
 
-        static SOCKET   sockets[8];
-        static int      socket_count;
         static tint     last_tick;
         static tbheap   send_queue;
 
@@ -420,6 +426,7 @@ namespace swift {
     int     Listen (Address addr);
     /** Run send/receive loop for the specified amount of time. */
     void    Loop (tint till);
+    bool    Listen3rdPartySocket (sckrwecb_t);
     /** Stop listening to a port. */
     void    Shutdown (int sock_des=-1);
 
@@ -447,7 +454,12 @@ namespace swift {
     /** Returns the number of bytes that are complete sequentially, starting from the
         beginning, till the first not-yet-retrieved packet. */
     uint64_t  SeqComplete (int fdes);
+    /***/
+    int       Find (Sha1Hash hash);
 
+    void AddProgressCallback (int transfer,ProgressCallback cb,uint8_t agg);
+    void RemoveProgressCallback (int transfer,ProgressCallback cb);
+    void ExternallyRetrieved (int transfer,bin64_t piece);
 
     //uint32_t Width (const tbinvec& v);