add .gitignore
[swift-upb.git] / swift.h
diff --git a/swift.h b/swift.h
index e6a8e57..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() {}
     };
 
@@ -316,7 +326,6 @@ namespace swift {
             return i<channels.size()?channels[i]:NULL;
         }
         static void CloseTransfer (FileTransfer* trans);
-        static SOCKET default_socket() { return sockets[0].sock; }
 
     protected:
         /** Channel id: index in the channel array. */
@@ -396,9 +405,6 @@ namespace swift {
 
         static PeerSelector* peer_selector;
 
-        #define SWFT_MAX_SOCK_OPEN 128
-        static socket_callbacks_t sockets[SWFT_MAX_SOCK_OPEN];
-        static int      socket_count;
         static tint     last_tick;
         static tbheap   send_queue;
 
@@ -410,7 +416,6 @@ namespace swift {
         friend void     AddPeer (Address address, const Sha1Hash& root);
         friend void     SetTracker(const Address& tracker);
         friend int      Open (const char*, const Sha1Hash&) ; // FIXME
-        friend bool     Listen3rdPartySocket (socket_callbacks_t);
 
     };
 
@@ -421,7 +426,7 @@ namespace swift {
     int     Listen (Address addr);
     /** Run send/receive loop for the specified amount of time. */
     void    Loop (tint till);
-    bool    Listen3rdPartySocket (socket_callbacks_t);
+    bool    Listen3rdPartySocket (sckrwecb_t);
     /** Stop listening to a port. */
     void    Shutdown (int sock_des=-1);
 
@@ -449,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);