Dropped HTTP reply support (not working)

This commit is contained in:
Uriziel 2014-04-19 11:39:17 +02:00
parent 36d2b432b9
commit 0b5b8811b4
4 changed files with 8 additions and 29 deletions

View File

@ -177,8 +177,6 @@ en = {
"server-motd-argument": "path to file from which motd will be fetched",
"server-messed-up-motd-unescaped-placeholders": "Message of the Day has unescaped placeholders. All $ signs should be doubled ($$).",
"server-messed-up-motd-too-long": "Message of the Day is too long - maximum of {} chars, {} given.",
"server-http-reply-argument": "path to file from which http reply will be fetched",
"server-default-http-reply": "This server should not be requested with your browser, but with Syncplay software available from http://syncplay.pl",
"server-irc-verbose": "Should server actively report changes in rooms",
"server-irc-config": "Path to irc bot config files",

View File

@ -32,11 +32,7 @@ class JSONCommandProtocol(LineReceiver):
try:
messages = json.loads(line)
except:
if ("GET / HTTP/1." in line):
self.handleHttpRequest(line)
self.drop()
else:
self.dropWithError(getMessage("en", "not-json-server-error").format(line))
self.dropWithError(getMessage("en", "not-json-server-error").format(line))
return
self.handleMessages(messages)
@ -190,9 +186,6 @@ class SyncClientProtocol(JSONCommandProtocol):
position, paused, doSeek, stateChange = self._client.getLocalState()
self.sendState(position, paused, doSeek, latencyCalculation, stateChange)
def handleHttpRequest(self, request):
pass
def sendState(self, position, paused, doSeek, latencyCalculation, stateChange=False):
state = {}
positionAndPausedIsSet = position is not None and paused is not None
@ -234,7 +227,7 @@ class SyncServerProtocol(JSONCommandProtocol):
self._pingService = PingService()
self._clientLatencyCalculation = 0
self._clientLatencyCalculationArrivalTime = 0
def __hash__(self):
return hash('|'.join((
self.transport.getPeer().host,
@ -364,7 +357,7 @@ class SyncServerProtocol(JSONCommandProtocol):
}
ping = {
"latencyCalculation": self._pingService.newTimestamp(),
"serverRtt": self._pingService.getRtt()
"serverRtt": self._pingService.getRtt()
}
if(self._clientLatencyCalculation):
ping["clientLatencyCalculation"] = self._clientLatencyCalculation + processingTime
@ -413,9 +406,6 @@ class SyncServerProtocol(JSONCommandProtocol):
if(self.serverIgnoringOnTheFly == 0):
self._factory.updateWatcherState(self, position, paused, doSeek, self._pingService.getLastForwardDelay())
def handleHttpRequest(self, request):
self.sendLine(self._factory.gethttpRequestReply())
def handleError(self, error):
self.dropWithError(error["message"]) # TODO: more processing and fallbacking
@ -443,9 +433,9 @@ class PingService(object):
self._avrRtt = self._rtt
self._avrRtt = self._avrRtt * PING_MOVING_AVERAGE_WEIGHT + self._rtt * (1 - PING_MOVING_AVERAGE_WEIGHT)
if(senderRtt < self._rtt):
self._fd = self._avrRtt/2 + (self._rtt - senderRtt)
self._fd = self._avrRtt / 2 + (self._rtt - senderRtt)
else:
self._fd = self._avrRtt/2
self._fd = self._avrRtt / 2
def getLastForwardDelay(self):
return self._fd

View File

@ -14,13 +14,12 @@ from string import Template
import argparse
class SyncFactory(Factory):
def __init__(self, password='', motdFilePath=None, httpReplyFilePath=None):
def __init__(self, password='', motdFilePath=None):
print getMessage("en", "welcome-server-notification").format(syncplay.version)
if(password):
password = hashlib.md5(password).hexdigest()
self.password = password
self._motdFilePath = motdFilePath
self._httpReplyFilePath = httpReplyFilePath
self._rooms = {}
self._roomStates = {}
self._roomUpdate = threading.RLock()
@ -108,13 +107,6 @@ class SyncFactory(Factory):
else:
return ""
def gethttpRequestReply(self):
if(self._httpReplyFilePath and os.path.isfile(self._httpReplyFilePath)):
tmpl = codecs.open(self._httpReplyFilePath, "r", "utf-8-sig").read()
return tmpl.encode('utf-8')
else:
return getMessage("en", "server-default-http-reply")
def sendState(self, watcherProtocol, doSeek=False, forcedUpdate=False):
watcher = self.getWatcher(watcherProtocol)
if(not watcher):
@ -296,4 +288,3 @@ class ConfigurationGetter(object):
self._argparser.add_argument('--password', metavar='password', type=str, nargs='?', help=getMessage("en", "server-password-argument"))
self._argparser.add_argument('--isolate-rooms', action='store_true', help=getMessage("en", "server-isolate-room-argument"))
self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-motd-argument"))
self._argparser.add_argument('--http-reply-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-http-reply-argument"))

View File

@ -13,7 +13,7 @@ argsGetter = ConfigurationGetter()
args = argsGetter.getConfiguration()
if(not args.isolate_rooms):
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file, args.http_reply_file))
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file))
else:
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file, args.http_reply_file))
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file))
reactor.run()