-
Notifications
You must be signed in to change notification settings - Fork 5
/
Nxt$User.java
103 lines (99 loc) · 3.18 KB
/
Nxt$User.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import javax.servlet.AsyncContext;
import javax.servlet.ServletResponse;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
class Nxt$User
{
final ConcurrentLinkedQueue<JSONObject> pendingResponses = new ConcurrentLinkedQueue();
AsyncContext asyncContext;
volatile boolean isInactive;
volatile String secretPhrase;
void deinitializeKeyPair()
{
this.secretPhrase = null;
}
BigInteger initializeKeyPair(String paramString)
throws Exception
{
this.secretPhrase = paramString;
byte[] arrayOfByte = MessageDigest.getInstance("SHA-256").digest(Nxt.Crypto.getPublicKey(paramString));
return new BigInteger(1, new byte[] { arrayOfByte[7], arrayOfByte[6], arrayOfByte[5], arrayOfByte[4], arrayOfByte[3], arrayOfByte[2], arrayOfByte[1], arrayOfByte[0] });
}
void send(JSONObject paramJSONObject)
{
synchronized (this)
{
if (this.asyncContext == null)
{
if (this.isInactive) {
return;
}
if (this.pendingResponses.size() > 1000)
{
this.pendingResponses.clear();
this.isInactive = true;
if (this.secretPhrase == null) {
Nxt.users.values().remove(this);
}
return;
}
this.pendingResponses.offer(paramJSONObject);
}
else
{
JSONArray localJSONArray = new JSONArray();
JSONObject localJSONObject1;
while ((localJSONObject1 = (JSONObject)this.pendingResponses.poll()) != null) {
localJSONArray.add(localJSONObject1);
}
localJSONArray.add(paramJSONObject);
JSONObject localJSONObject2 = new JSONObject();
localJSONObject2.put("responses", localJSONArray);
try
{
this.asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
PrintWriter localPrintWriter = this.asyncContext.getResponse().getWriter();
Object localObject1 = null;
try
{
localJSONObject2.writeJSONString(localPrintWriter);
}
catch (Throwable localThrowable2)
{
localObject1 = localThrowable2;
throw localThrowable2;
}
finally
{
if (localPrintWriter != null) {
if (localObject1 != null) {
try
{
localPrintWriter.close();
}
catch (Throwable localThrowable3)
{
localObject1.addSuppressed(localThrowable3);
}
} else {
localPrintWriter.close();
}
}
}
this.asyncContext.complete();
this.asyncContext = null;
}
catch (Exception localException)
{
Nxt.logMessage("17: " + localException.toString());
}
}
}
}