Rev536, Fix stats page, Support ranged http requests for better video browser compatibility, setHashfield command, One by one send hashfield to connected peers if changed, Keep count hashfield changetime, PeerHashfield optimalizations, Wait for peers on checkmodification, Give more time to query trackers, Do not count udp trackers as error if udp disabled, Test hashfield push
This commit is contained in:
parent
9c5fda6ed2
commit
8e710beab1
9 changed files with 171 additions and 40 deletions
src/File
|
@ -1,5 +1,6 @@
|
|||
# Included modules
|
||||
import os
|
||||
import time
|
||||
from cStringIO import StringIO
|
||||
|
||||
# Third party modules
|
||||
|
@ -69,6 +70,8 @@ class FileRequest(object):
|
|||
self.actionGetHashfield(params)
|
||||
elif cmd == "findHashIds":
|
||||
self.actionFindHashIds(params)
|
||||
elif cmd == "setHashfield":
|
||||
self.actionSetHashfield(params)
|
||||
elif cmd == "ping":
|
||||
self.actionPing()
|
||||
else:
|
||||
|
@ -268,9 +271,11 @@ class FileRequest(object):
|
|||
return False
|
||||
|
||||
# Add peer to site if not added before
|
||||
connected_peer = site.addPeer(self.connection.ip, self.connection.port)
|
||||
if connected_peer: # Just added
|
||||
connected_peer.connect(self.connection) # Assign current connection to peer
|
||||
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True)
|
||||
if not peer.connection: # Just added
|
||||
peer.connect(self.connection) # Assign current connection to peer
|
||||
|
||||
peer.time_my_hashfield_sent = time.time() # Don't send again if not changed
|
||||
|
||||
self.response({"hashfield_raw": site.content_manager.hashfield.tostring()})
|
||||
|
||||
|
@ -297,6 +302,18 @@ class FileRequest(object):
|
|||
)
|
||||
self.response({"peers": back})
|
||||
|
||||
def actionSetHashfield(self, params):
|
||||
site = self.sites.get(params["site"])
|
||||
if not site or not site.settings["serving"]: # Site unknown or not serving
|
||||
self.response({"error": "Unknown site"})
|
||||
return False
|
||||
|
||||
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer
|
||||
if not peer.connection:
|
||||
peer.connect(self.connection)
|
||||
peer.hashfield.replaceFromString(params["hashfield_raw"])
|
||||
self.response({"ok": "Updated"})
|
||||
|
||||
# Send a simple Pong! answer
|
||||
def actionPing(self):
|
||||
self.response("Pong!")
|
||||
|
|
|
@ -172,7 +172,7 @@ class FileServer(ConnectionServer):
|
|||
import gc
|
||||
first_announce = True # First start
|
||||
while 1:
|
||||
# Sites healthcare
|
||||
# Sites healthcare every 20 min
|
||||
if config.trackers_file:
|
||||
config.loadTrackersFile()
|
||||
for address, site in self.sites.items():
|
||||
|
@ -196,6 +196,9 @@ class FileServer(ConnectionServer):
|
|||
if self.port_opened is False:
|
||||
site.needConnections()
|
||||
|
||||
if first_announce: # Send my optional files to peers
|
||||
site.sendMyHashfield()
|
||||
|
||||
time.sleep(2) # Prevent too quick request
|
||||
|
||||
site = None
|
||||
|
@ -208,6 +211,7 @@ class FileServer(ConnectionServer):
|
|||
config.loadTrackersFile()
|
||||
for address, site in self.sites.items():
|
||||
site.announce(num=1, pex=False)
|
||||
site.sendMyHashfield(num_send=1)
|
||||
time.sleep(2)
|
||||
|
||||
first_announce = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue