-
Notifications
You must be signed in to change notification settings - Fork 6
/
RPC.java
66 lines (60 loc) · 1.8 KB
/
RPC.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
/*
* Curecoin 2.0.0a Source Code
* Copyright (c) 2015 Curecoin Developers
* Distributed under MIT License
* Requires Apache Commons Library
* Supports Java 1.7+
*/
import java.net.*;
import java.util.*;
/**
* The RPC object handles or delegates network communication for all RPC requests.
* RPC requests are stored in a public class variable, and RPC responses are placed into another public class variable.
* In the future, a queue system will exist, allowing for high-volume RPC calls.
* Additionally, the RPC currently provides no security. In the final release, RPC will require authentication.
* RPC calls are used to send and receive coins, as well as publish blocks.
*/
public class RPC extends Thread
{
private int listenPort;
public String request = null;
public ArrayList<RPCThread> rpcThreads;
public boolean shouldRun = true;
/**
* Standard RPC port is 8016, one above the P2P networking port.
*/
public RPC()
{
this.listenPort = 8016;
this.rpcThreads = new ArrayList<RPCThread>();
}
/**
* Alternate, currently-unused constructor to listen on a non-standard RPC port.
*
* @param listenPort Port to listen on
*/
public RPC(int listenPort)
{
this.listenPort = listenPort;
this.rpcThreads = new ArrayList<RPCThread>();
}
/**
* Starts listening and handles RPCThreads.
*/
public void run()
{
try
{
ServerSocket socket = new ServerSocket(listenPort);
while (shouldRun)
{
rpcThreads.add(new RPCThread(socket.accept()));
rpcThreads.get(rpcThreads.size() - 1).start();
}
socket.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
}