From 4b20e3e4663d94f89883e81ff06e86d33b32c554 Mon Sep 17 00:00:00 2001 From: Hydrus Network Developer Date: Sun, 18 Dec 2022 15:06:34 -0600 Subject: [PATCH] PTR Upload Patch Fixes the 500 error v510 clients are seeing when they upload to the PTR. --- hydrus/core/HydrusConstants.py | 3 + hydrus/core/HydrusSerialisable.py | 82 ++++++++++++++++++++++++- hydrus/core/networking/HydrusNetwork.py | 3 + hydrus/hydrus_client.py | 2 + hydrus/hydrus_server.py | 3 + 5 files changed, 92 insertions(+), 1 deletion(-) diff --git a/hydrus/core/HydrusConstants.py b/hydrus/core/HydrusConstants.py index 1ac03395..b6481ae9 100644 --- a/hydrus/core/HydrusConstants.py +++ b/hydrus/core/HydrusConstants.py @@ -7,6 +7,9 @@ import yaml # old method of getting frozen dir, doesn't work for symlinks looks like: # BASE_DIR = getattr( sys, '_MEIPASS', None ) +RUNNING_CLIENT = False +RUNNING_SERVER = False + RUNNING_FROM_FROZEN_BUILD = getattr( sys, 'frozen', False ) if RUNNING_FROM_FROZEN_BUILD: diff --git a/hydrus/core/HydrusSerialisable.py b/hydrus/core/HydrusSerialisable.py index f4684270..925142a6 100644 --- a/hydrus/core/HydrusSerialisable.py +++ b/hydrus/core/HydrusSerialisable.py @@ -3,6 +3,7 @@ import json import os from hydrus.core import HydrusCompression +from hydrus.core import HydrusConstants as HC from hydrus.core import HydrusData from hydrus.core import HydrusExceptions @@ -377,13 +378,60 @@ class SerialisableDictionary( SerialisableBase, dict ): SERIALISABLE_TYPE = SERIALISABLE_TYPE_DICTIONARY SERIALISABLE_NAME = 'Serialisable Dictionary' - SERIALISABLE_VERSION = 2 + SERIALISABLE_VERSION = 2 # this is used in the network, do not update it casually! def __init__( self, *args, **kwargs ): dict.__init__( self, *args, **kwargs ) SerialisableBase.__init__( self ) + def _GetSerialisableInfoVersion1( self ): + + simple_key_simple_value_pairs = [] + simple_key_serialisable_value_pairs = [] + serialisable_key_simple_value_pairs = [] + serialisable_key_serialisable_value_pairs = [] + + for ( key, value ) in self.items(): + + if isinstance( key, SerialisableBase ): + + serialisable_key = key.GetSerialisableTuple() + + if isinstance( value, SerialisableBase ): + + serialisable_value = value.GetSerialisableTuple() + + serialisable_key_serialisable_value_pairs.append( ( serialisable_key, serialisable_value ) ) + + else: + + serialisable_value = value + + serialisable_key_simple_value_pairs.append( ( serialisable_key, serialisable_value ) ) + + + else: + + serialisable_key = key + + if isinstance( value, SerialisableBase ): + + serialisable_value = value.GetSerialisableTuple() + + simple_key_serialisable_value_pairs.append( ( serialisable_key, serialisable_value ) ) + + else: + + serialisable_value = value + + simple_key_simple_value_pairs.append( ( serialisable_key, serialisable_value ) ) + + + + + return ( simple_key_simple_value_pairs, simple_key_serialisable_value_pairs, serialisable_key_simple_value_pairs, serialisable_key_serialisable_value_pairs ) + def _GetSerialisableInfo( self ): @@ -475,6 +523,38 @@ class SerialisableDictionary( SerialisableBase, dict ): + def GetSerialisableTuple( self ): + + # TODO: delete this around version 537 + # this is a patch to deal with me foolishly updating SerialisableDictionary without thinking that it is used in network comms + # the server suddenly starts giving version 2 Dicts, and old clients can't handle it! + # therefore, we are patching this to give a version 1 result if we are the server. we don't transport bytes stuff over network yet, nor store bytes in server services dict, so it is ok + # we are doing this for version 511, so let's give lads ~26 weeks to update + + if HC.RUNNING_SERVER: + + serialisable_info = self._GetSerialisableInfoVersion1() + + return ( self.SERIALISABLE_TYPE, 1, serialisable_info ) + + else: + + if hasattr( self, '_lock' ): + + with getattr( self, '_lock' ): + + serialisable_info = self._GetSerialisableInfo() + + + else: + + serialisable_info = self._GetSerialisableInfo() + + + return ( self.SERIALISABLE_TYPE, self.SERIALISABLE_VERSION, serialisable_info ) + + + SERIALISABLE_TYPES_TO_OBJECT_TYPES[ SERIALISABLE_TYPE_DICTIONARY ] = SerialisableDictionary diff --git a/hydrus/core/networking/HydrusNetwork.py b/hydrus/core/networking/HydrusNetwork.py index 01ed1fdb..092a4970 100644 --- a/hydrus/core/networking/HydrusNetwork.py +++ b/hydrus/core/networking/HydrusNetwork.py @@ -20,6 +20,9 @@ MAX_NULLIFICATION_PERIOD = 86400 * 365 def GenerateDefaultServiceDictionary( service_type ): + # don't store bytes key/value data here until ~version 537 + # the server kicks out a patched version 1 of serialisabledict, so it can't handle byte gubbins, lad + dictionary = HydrusSerialisable.SerialisableDictionary() dictionary[ 'upnp_port' ] = None diff --git a/hydrus/hydrus_client.py b/hydrus/hydrus_client.py index 3e1bf85d..9142aa27 100644 --- a/hydrus/hydrus_client.py +++ b/hydrus/hydrus_client.py @@ -25,6 +25,8 @@ try: from hydrus.core import HydrusConstants as HC + HC.RUNNING_CLIENT = True + from hydrus.core import HydrusData from hydrus.core import HydrusGlobals as HG from hydrus.core import HydrusLogger diff --git a/hydrus/hydrus_server.py b/hydrus/hydrus_server.py index a6c50f94..eb60eb11 100644 --- a/hydrus/hydrus_server.py +++ b/hydrus/hydrus_server.py @@ -23,6 +23,9 @@ try: HydrusBoot.AddBaseDirToEnvPath() from hydrus.core import HydrusConstants as HC + + HC.RUNNING_SERVER = True + from hydrus.core import HydrusExceptions from hydrus.core import HydrusData from hydrus.core import HydrusGlobals as HG