@@ -44,14 +44,14 @@ public void onProxyInitialization(@NotNull ProxyServer proxy) {
4444 final Set <String > blacklistSet = new HashSet <>();
4545
4646 final String mirror = config .get ("mirror" , null );
47+ final long interval = getMirrorInterval (config .get ("mirror_interval" , "interval_2" ));
4748 if (mirror != null && !mirror .trim ().isEmpty ()) {
48- if ((System .currentTimeMillis () - config .getLong ("last_mirror_load" , 0 )) <
49- getMirrorInterval (config .get ("mirror_interval" , "interval_2" ))) {
49+ if ((System .currentTimeMillis () - config .getLong ("last_mirror_load" , 0 )) < interval ) {
5050 if (!loadBlacklistFromCache (blacklistSet )) {
51- loadBlacklistFromMirror (blacklistSet , mirror , config );
51+ loadBlacklistFromMirror (blacklistSet , mirror , config , interval != 0 );
5252 }
5353 } else {
54- if (!loadBlacklistFromMirror (blacklistSet , mirror , config )) {
54+ if (!loadBlacklistFromMirror (blacklistSet , mirror , config , interval != 0 )) {
5555 loadBlacklistFromCache (blacklistSet );
5656 }
5757 }
@@ -67,6 +67,7 @@ public void onProxyInitialization(@NotNull ProxyServer proxy) {
6767 final String [] blacklist = blacklistSet .toArray (new String [0 ]);
6868
6969 LOGGER .info ("Loaded {} blocked websites" , blacklist .length );
70+ LOGGER .info ("Len: {}, 1st: '{}'" , blacklist .length , blacklist [0 ]);
7071
7172 final boolean enableSni = config .getBoolean ("modify_sni" , false );
7273 if (enableSni ) {
@@ -109,21 +110,23 @@ public void onProxyStatusChanged(@NotNull ProxyStatus status) {
109110 }
110111 }
111112
112- private boolean loadBlacklistFromMirror (Set <String > blacklist , String mirror , Configuration config ) {
113+ private boolean loadBlacklistFromMirror (Set <String > blacklist , String mirror , Configuration config , boolean caching ) {
113114 LOGGER .info ("Loading blacklist from mirror..." );
114115 try {
115116 final String raw = TextReader .read (new URL (mirror ).openStream ());
116117 blacklist .addAll (Arrays .asList (raw .split ("\n " )));
117- try {
118- config .setLong ("last_mirror_load" , System .currentTimeMillis ());
119- saveConfiguration ();
120- } catch (IOException ex ) {
121- LOGGER .warn ("Failed to save the time of the last load of the blacklist from the mirror: {}" , ex .getMessage (), ex );
122- }
123- try {
124- saveTextFile ("government-blacklist-cache.txt" , raw );
125- } catch (IOException ex ) {
126- LOGGER .warn ("Failed to save cached blacklist: {}" , ex .getMessage (), ex );
118+ if (caching ) {
119+ try {
120+ config .setLong ("last_mirror_load" , System .currentTimeMillis ());
121+ saveConfiguration ();
122+ } catch (IOException ex ) {
123+ LOGGER .warn ("Failed to save the time of the last load of the blacklist from the mirror: {}" , ex .getMessage (), ex );
124+ }
125+ try {
126+ saveTextFile ("government-blacklist-cache.txt" , raw );
127+ } catch (IOException ex ) {
128+ LOGGER .warn ("Failed to save cached blacklist: {}" , ex .getMessage (), ex );
129+ }
127130 }
128131 return true ;
129132 } catch (IOException ex ) {
0 commit comments