12
12
import de .dytanic .cloudnet .cloudflare .util .DNSType ;
13
13
import de .dytanic .cloudnet .cloudflare .util .DefaultDNSRecord ;
14
14
import de .dytanic .cloudnet .cloudflare .util .SRVRecord ;
15
+ import de .dytanic .cloudnet .lib .MultiValue ;
15
16
import de .dytanic .cloudnet .lib .NetworkUtils ;
16
- import de .dytanic .cloudnet .lib .database .Database ;
17
17
import de .dytanic .cloudnet .lib .server .ProxyGroup ;
18
18
import de .dytanic .cloudnet .lib .server .ProxyProcessMeta ;
19
19
import de .dytanic .cloudnet .lib .service .SimpledWrapperInfo ;
20
+ import de .dytanic .cloudnet .lib .utility .Acceptable ;
20
21
import de .dytanic .cloudnet .lib .utility .CollectionWrapper ;
21
22
import de .dytanic .cloudnet .lib .utility .document .Document ;
22
23
import lombok .Getter ;
@@ -42,9 +43,9 @@ public class CloudFlareService {
42
43
private Collection <CloudFlareConfig > cloudFlareConfigs ;
43
44
44
45
// WrapperId DNSRecord
45
- private final Map <String , PostResponse >
46
- ipARecords = NetworkUtils . newConcurrentHashMap (),
47
- bungeeSRVRecords = NetworkUtils .newConcurrentHashMap ();
46
+ private final Map <String , MultiValue < PostResponse , String >> ipARecords = NetworkUtils . newConcurrentHashMap ();
47
+
48
+ private final Map < String , MultiValue < PostResponse , String >> bungeeSRVRecords = NetworkUtils .newConcurrentHashMap ();
48
49
49
50
/**
50
51
* Constructs a new CloudFlare Service module with a given configuration.
@@ -61,12 +62,8 @@ public CloudFlareService(Collection<CloudFlareConfig> cloudFlareConfigs)
61
62
@ Deprecated
62
63
public boolean bootstrap (Map <String , SimpledWrapperInfo > wrapperInfoMap , Map <String , ProxyGroup > groups , CloudFlareDatabase cloudFlareDatabase )
63
64
{
64
- for (PostResponse id : cloudFlareDatabase .getAndRemove ().values ())
65
- this .deleteRecord (id );
66
-
67
- for (String key : cloudFlareDatabase .getAll ())
68
- if (!key .equalsIgnoreCase (Database .UNIQUE_NAME_KEY ) && !wrapperInfoMap .containsKey (key ))
69
- deleteRecord (cloudFlareDatabase .getResponse (key ));
65
+ for (MultiValue <PostResponse , String > id : cloudFlareDatabase .getAndRemove ().values ())
66
+ this .deleteRecord (id .getFirst ());
70
67
71
68
for (CloudFlareConfig cloudFlareConfig : this .cloudFlareConfigs )
72
69
if (cloudFlareConfig .isEnabled ())
@@ -75,15 +72,15 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str
75
72
ProxyGroup proxyGroup = groups .get (cloudFlareProxyGroup .getName ());
76
73
for (String wrapper : proxyGroup .getWrapper ())
77
74
{
78
- if (!cloudFlareDatabase .contains (wrapper ))
75
+ if (!cloudFlareDatabase .contains (cloudFlareConfig , wrapper )) //TODO
79
76
{
80
77
String host = wrapperInfoMap .get (wrapper ).getHostName ();
81
78
DNSRecord dnsRecord = new DefaultDNSRecord (DNSType .A , wrapper + "." + cloudFlareConfig .getDomainName (), host , new Document ().obj ());
82
79
if (!ipARecords .containsKey (wrapper ))
83
80
{
84
81
PostResponse postResponse = this .createRecord (cloudFlareConfig , dnsRecord );
85
- ipARecords .put (wrapper , postResponse );
86
- cloudFlareDatabase .putPostResponse (wrapper , postResponse );
82
+ ipARecords .put (postResponse . getId (), new MultiValue <>( postResponse , wrapper ) );
83
+ cloudFlareDatabase .putPostResponse (new MultiValue <>( postResponse , wrapper ) );
87
84
NetworkUtils .sleepUninterruptedly (400 );
88
85
}
89
86
}
@@ -94,16 +91,22 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str
94
91
95
92
public boolean shutdown (CloudFlareDatabase cloudFlareDatabase )
96
93
{
97
- for (PostResponse postResponse : this .bungeeSRVRecords .values ())
94
+ for (MultiValue < PostResponse , String > postResponse : this .bungeeSRVRecords .values ())
98
95
{
99
- this .deleteRecord (postResponse );
100
- NetworkUtils .sleepUninterruptedly (450 );
96
+ try
97
+ {
98
+ this .deleteRecord (postResponse .getFirst ());
99
+ NetworkUtils .sleepUninterruptedly (500 );
100
+ } catch (Exception ex )
101
+ {
102
+ ex .printStackTrace ();
103
+ }
101
104
}
102
105
103
- for (PostResponse id : cloudFlareDatabase .getAndRemove ().values ())
106
+ for (MultiValue < PostResponse , String > id : cloudFlareDatabase .getAndRemove ().values ())
104
107
{
105
- this .deleteRecord (id );
106
- NetworkUtils .sleepUninterruptedly (450 );
108
+ this .deleteRecord (id . getFirst () );
109
+ NetworkUtils .sleepUninterruptedly (500 );
107
110
}
108
111
return true ;
109
112
}
@@ -163,9 +166,9 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
163
166
proxyServer .getServiceId ().getWrapperId () + "." + cloudFlareConfig .getDomainName ()
164
167
);
165
168
}
166
- PostResponse postResponse1 = this .createRecord (cloudFlareConfig , srvRecord );
167
- cloudFlareDatabase .add (postResponse1 );
168
- this .bungeeSRVRecords .put (proxyServer .getServiceId ().getServerId (), postResponse1 );
169
+ PostResponse postResponse = this .createRecord (cloudFlareConfig , srvRecord );
170
+ cloudFlareDatabase .add (postResponse );
171
+ this .bungeeSRVRecords .put (postResponse . getId (), new MultiValue <>( postResponse , proxyServer .getServiceId ().getServerId ()) );
169
172
}
170
173
}
171
174
}
@@ -178,13 +181,24 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
178
181
*/
179
182
public void removeProxy (ProxyProcessMeta proxyServer , CloudFlareDatabase cloudFlareDatabase )
180
183
{
181
- if (!bungeeSRVRecords .containsKey (proxyServer .getServiceId ().getServerId ())) return ;
184
+ // if (!bungeeSRVRecords.containsKey(proxyServer.getServiceId().getServerId())) return;
182
185
183
- PostResponse postResponse = bungeeSRVRecords .get (proxyServer .getServiceId ().getServerId ());
184
- if (postResponse != null )
186
+ while (true )
185
187
{
186
- cloudFlareDatabase .remove (postResponse .getId ());
187
- deleteRecord (postResponse );
188
+ MultiValue <PostResponse , String > postResponse = CollectionWrapper .filter (bungeeSRVRecords .values (), new Acceptable <MultiValue <PostResponse , String >>() {
189
+ @ Override
190
+ public boolean isAccepted (MultiValue <PostResponse , String > postResponseStringMultiValue )
191
+ {
192
+ return postResponseStringMultiValue .getSecond ().equalsIgnoreCase (proxyServer .getServiceId ().getServerId ());
193
+ }
194
+ });
195
+
196
+ //MultiValue<PostResponse, String> postResponse = bungeeSRVRecords.get(proxyServer.getServiceId().getServerId());
197
+ if (postResponse != null )
198
+ {
199
+ cloudFlareDatabase .remove (postResponse .getFirst ().getId ());
200
+ deleteRecord (postResponse .getFirst ());
201
+ } else break ;
188
202
}
189
203
}
190
204
@@ -231,6 +245,7 @@ public PostResponse createRecord(CloudFlareConfig cloudFlareConfig, DNSRecord dn
231
245
{
232
246
e .printStackTrace ();
233
247
}
248
+
234
249
return null ;
235
250
}
236
251
0 commit comments