Updated latest changes.

Changed console logic.
Fixed event broadcast bug where same message was sent to multiple listeners.
Added local test node.
This commit is contained in:
Adrian Tiberius 2015-08-23 01:14:25 +02:00
parent 9fc5e932bc
commit c245891abb
19 changed files with 354 additions and 392 deletions

View File

@ -2,6 +2,7 @@ package org.ethereum.android_app;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod; import android.text.method.ScrollingMovementMethod;
@ -10,30 +11,25 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.ethereum.android.EthereumManager;
import org.ethereum.listener.EthereumListenerAdapter;
public class ConsoleFragment extends Fragment implements FragmentInterface { public class ConsoleFragment extends Fragment implements FragmentInterface {
EthereumManager ethereumManager;
private TextView console; private TextView console;
TextViewUpdater consoleUpdater = new TextViewUpdater(); private final static int CONSOLE_LENGTH = 10000;
private final static int CONSOLE_REFRESH_MILLS = 1000 * 5; //5 sec
private class TextViewUpdater implements Runnable { private Handler handler = new Handler();
private String txt;
private Runnable mRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
console.setText(txt); console.setText(EthereumApplication.log);
} handler.postDelayed(mRunnable, CONSOLE_REFRESH_MILLS);
public void setText(String txt) {
this.txt = txt;
}
} }
};
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -41,6 +37,18 @@ public class ConsoleFragment extends Fragment implements FragmentInterface {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@Override
public void onPause() {
super.onPause();
handler.removeCallbacksAndMessages(null);
}
@Override
public void onResume() {
super.onResume();
handler.post(mRunnable);
}
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
@ -58,9 +66,8 @@ public class ConsoleFragment extends Fragment implements FragmentInterface {
return view; return view;
} }
@Override
public void onMessage(String message) { public void onMessage(String message) {
System.out.println(message);
consoleUpdater.setText(message);
ConsoleFragment.this.console.post(consoleUpdater);
} }
} }

View File

@ -1,54 +1,172 @@
package org.ethereum.android_app; package org.ethereum.android_app;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.support.multidex.MultiDexApplication; import android.support.multidex.MultiDexApplication;
import org.ethereum.android.service.ConnectorHandler; import org.ethereum.android.service.ConnectorHandler;
import org.ethereum.android.service.EthereumClientMessage;
import org.ethereum.android.service.EthereumConnector; import org.ethereum.android.service.EthereumConnector;
import org.ethereum.android.service.events.BlockEventData;
import org.ethereum.android.service.events.EventData;
import org.ethereum.android.service.events.EventFlag;
import org.ethereum.android.service.events.MessageEventData;
import org.ethereum.android.service.events.PeerDisconnectEventData;
import org.ethereum.android.service.events.PendingTransactionsEventData;
import org.ethereum.android.service.events.TraceEventData;
import org.ethereum.android.service.events.VMTraceCreatedEventData;
import org.ethereum.net.p2p.HelloMessage;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EnumSet;
import java.util.UUID;
public class EthereumApplication extends MultiDexApplication implements ConnectorHandler { public class EthereumApplication extends MultiDexApplication implements ConnectorHandler {
private final static int CONSOLE_LENGTH = 10000;
public static EthereumConnector ethereum = null; public static EthereumConnector ethereum = null;
public static String log = ""; public static String log = "";
public static String identifier = UUID.randomUUID().toString();
static DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
@Override public void onCreate() { @Override public void onCreate() {
super.onCreate(); super.onCreate();
if (ethereum == null) { if (ethereum == null) {
ethereum = new EthereumConnector(this, EthereumService.class); ethereum = new EthereumConnector(this, EthereumService.class);
}
ethereum.registerHandler(this); ethereum.registerHandler(this);
ethereum.bindService(); ethereum.bindService();
} }
}
@Override @Override
public void onTerminate() { public void onTerminate() {
super.onTerminate(); super.onTerminate();
ethereum.removeHandler(this); ethereum.removeHandler(this);
ethereum.removeListener(identifier);
ethereum.unbindService(); ethereum.unbindService();
ethereum = null; ethereum = null;
} }
@Override @Override
public void onConnectorConnected() { public void onConnectorConnected() {
System.out.println("Connector connected"); System.out.println("Connector connected");
ethereum.addListener(identifier, EnumSet.allOf(EventFlag.class));
} }
@Override @Override
public void onConnectorDisconnected() { public void onConnectorDisconnected() {
} }
@Override @Override
public String getID() { public String getID() {
return "1"; return identifier;
}
protected class MessageProcessTask extends AsyncTask<Void, Void, Void> {
Message message = null;
public MessageProcessTask(Message message) {
this.message = message;
}
protected Void doInBackground(Void... args) {
processMessage(message);
return null;
}
protected void onPostExecute(Void results) {
}
}
protected void processMessage(Message message) {
Bundle data = message.getData();
data.setClassLoader(EventFlag.class.getClassLoader());
EventFlag event = (EventFlag)data.getSerializable("event");
EventData eventData;
MessageEventData messageEventData;
switch(event) {
case EVENT_BLOCK:
BlockEventData blockEventData = data.getParcelable("data");
addLogEntry(blockEventData.registeredTime, "Added block with " + blockEventData.receipts.size() + " transaction receipts.");
break;
case EVENT_HANDSHAKE_PEER:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Peer " + new HelloMessage(messageEventData.message).getPeerId() + " said hello");
break;
case EVENT_NO_CONNECTIONS:
eventData = data.getParcelable("data");
addLogEntry(eventData.registeredTime, "No connections");
break;
case EVENT_PEER_DISCONNECT:
PeerDisconnectEventData peerDisconnectEventData = data.getParcelable("data");
addLogEntry(peerDisconnectEventData.registeredTime, "Peer " + peerDisconnectEventData.host + ":" + peerDisconnectEventData.port + " disconnected.");
break;
case EVENT_PENDING_TRANSACTIONS_RECEIVED:
PendingTransactionsEventData pendingTransactionsEventData = data.getParcelable("data");
addLogEntry(pendingTransactionsEventData.registeredTime, "Received " + pendingTransactionsEventData.transactions.size() + " pending transactions");
break;
case EVENT_RECEIVE_MESSAGE:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Received message: " + messageEventData.messageClass.getName());
break;
case EVENT_SEND_MESSAGE:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Sent message: " + messageEventData.messageClass.getName());
break;
case EVENT_SYNC_DONE:
eventData = data.getParcelable("data");
addLogEntry(eventData.registeredTime, "Sync done");
break;
case EVENT_VM_TRACE_CREATED:
VMTraceCreatedEventData vmTraceCreatedEventData = data.getParcelable("data");
addLogEntry(vmTraceCreatedEventData.registeredTime, "CM trace created: " + vmTraceCreatedEventData.transactionHash + " - " + vmTraceCreatedEventData.trace);
break;
case EVENT_TRACE:
TraceEventData traceEventData = data.getParcelable("data");
addLogEntry(traceEventData.registeredTime, traceEventData.message);
break;
}
} }
@Override @Override
public boolean handleMessage(Message message) { public boolean handleMessage(final Message message) {
System.out.println(message.toString()); boolean isClaimed = true;
return true; switch(message.what) {
case EthereumClientMessage.MSG_EVENT:
Message messageCopy = new Message();
messageCopy.copyFrom(message);
new MessageProcessTask(messageCopy).execute();
break;
default:
isClaimed = false;
}
return isClaimed;
}
protected void addLogEntry(long timestamp, String message) {
Date date = new Date(timestamp);
String logEntry = formatter.format(date) + " -> " + message + "\n\n";
EthereumApplication.log += logEntry;
if (EthereumApplication.log.length() > CONSOLE_LENGTH) {
EthereumApplication.log = EthereumApplication.log.substring(CONSOLE_LENGTH);
}
} }
} }

View File

@ -1,43 +1,21 @@
package org.ethereum.android_app; package org.ethereum.android_app;
import android.os.Message;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import org.ethereum.android.service.ConnectorHandler;
import org.ethereum.android.service.EthereumClientMessage;
import org.ethereum.android.service.events.BlockEventData;
import org.ethereum.android.service.events.EventData;
import org.ethereum.android.service.events.EventFlag;
import org.ethereum.android.service.events.MessageEventData;
import org.ethereum.android.service.events.PeerDisconnectEventData;
import org.ethereum.android.service.events.PendingTransactionsEventData;
import org.ethereum.android.service.events.TraceEventData;
import org.ethereum.android.service.events.VMTraceCreatedEventData;
import org.ethereum.config.SystemProperties;
import org.ethereum.net.p2p.HelloMessage;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
import java.util.UUID;
public class RemoteMainActivity extends ActionBarActivity implements ActivityInterface, ConnectorHandler { public class RemoteMainActivity extends ActionBarActivity implements ActivityInterface {
private Toolbar toolbar; private Toolbar toolbar;
private ViewPager viewPager; private ViewPager viewPager;
private SlidingTabLayout tabs; private SlidingTabLayout tabs;
private TabsPagerAdapter adapter; private TabsPagerAdapter adapter;
protected ArrayList<FragmentInterface> fragments = new ArrayList<>(); protected ArrayList<FragmentInterface> fragments = new ArrayList<>();
protected String handlerIdentifier = UUID.randomUUID().toString();
static DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -55,7 +33,7 @@ public class RemoteMainActivity extends ActionBarActivity implements ActivityInt
tabs = (SlidingTabLayout) findViewById(R.id.tabs); tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); tabs.setDistributeEvenly(true);
tabs.setViewPager(viewPager); tabs.setViewPager(viewPager);
EthereumApplication.ethereum.registerHandler(this);
} }
@Override @Override
@ -89,95 +67,4 @@ public class RemoteMainActivity extends ActionBarActivity implements ActivityInt
} }
} }
@Override
public boolean handleMessage(Message message) {
boolean isClaimed = true;
switch(message.what) {
case EthereumClientMessage.MSG_EVENT:
Bundle data = message.getData();
data.setClassLoader(EventFlag.class.getClassLoader());
EventFlag event = (EventFlag)data.getSerializable("event");
EventData eventData;
MessageEventData messageEventData;
switch(event) {
case EVENT_BLOCK:
BlockEventData blockEventData = data.getParcelable("data");
addLogEntry(blockEventData.registeredTime, "Added block with " + blockEventData.receipts.size() + " transaction receipts.");
break;
case EVENT_HANDSHAKE_PEER:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Peer " + new HelloMessage(messageEventData.message).getPeerId() + " said hello");
break;
case EVENT_NO_CONNECTIONS:
eventData = data.getParcelable("data");
addLogEntry(eventData.registeredTime, "No connections");
break;
case EVENT_PEER_DISCONNECT:
PeerDisconnectEventData peerDisconnectEventData = data.getParcelable("data");
addLogEntry(peerDisconnectEventData.registeredTime, "Peer " + peerDisconnectEventData.host + ":" + peerDisconnectEventData.port + " disconnected.");
break;
case EVENT_PENDING_TRANSACTIONS_RECEIVED:
PendingTransactionsEventData pendingTransactionsEventData = data.getParcelable("data");
addLogEntry(pendingTransactionsEventData.registeredTime, "Received " + pendingTransactionsEventData.transactions.size() + " pending transactions");
break;
case EVENT_RECEIVE_MESSAGE:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Received message: " + messageEventData.messageClass.getName());
break;
case EVENT_SEND_MESSAGE:
messageEventData = data.getParcelable("data");
addLogEntry(messageEventData.registeredTime, "Sent message: " + messageEventData.messageClass.getName());
break;
case EVENT_SYNC_DONE:
eventData = data.getParcelable("data");
addLogEntry(eventData.registeredTime, "Sync done");
break;
case EVENT_VM_TRACE_CREATED:
VMTraceCreatedEventData vmTraceCreatedEventData = data.getParcelable("data");
addLogEntry(vmTraceCreatedEventData.registeredTime, "CM trace created: " + vmTraceCreatedEventData.transactionHash + " - " + vmTraceCreatedEventData.trace);
break;
case EVENT_TRACE:
TraceEventData traceEventData = data.getParcelable("data");
addLogEntry(traceEventData.registeredTime, traceEventData.message);
break;
}
break;
default:
isClaimed = false;
}
return isClaimed;
}
protected void addLogEntry(long timestamp, String message) {
Date date = new Date(timestamp);
EthereumApplication.log += formatter.format(date) + " -> " + message + "\n\n";
if (EthereumApplication.log.length() > 10000) {
EthereumApplication.log = EthereumApplication.log.substring(5000);
}
for(FragmentInterface fragment: fragments) {
fragment.onMessage(EthereumApplication.log);
}
}
@Override
public String getID() {
return handlerIdentifier;
}
@Override
public void onConnectorConnected() {
EthereumApplication.ethereum.addListener(handlerIdentifier, EnumSet.allOf(EventFlag.class));
//app.ethereum.connect(SystemProperties.CONFIG.activePeerIP(), SystemProperties.CONFIG.activePeerPort(), SystemProperties.CONFIG.activePeerNodeid());
//app.ethereum.startJsonRpc();
}
@Override
public void onConnectorDisconnected() {
}
} }

View File

@ -56,8 +56,7 @@ public class TestsFragment extends Fragment implements ConnectorHandler {
getEthereumStatus.setOnClickListener(onClickListener); getEthereumStatus.setOnClickListener(onClickListener);
getBlockchainStatus.setOnClickListener(onClickListener); getBlockchainStatus.setOnClickListener(onClickListener);
EthereumApplication app = (EthereumApplication)getActivity().getApplication(); EthereumApplication.ethereum.registerHandler(this);
app.ethereum.registerHandler(this);
return view; return view;
} }
@ -66,17 +65,16 @@ public class TestsFragment extends Fragment implements ConnectorHandler {
@Override @Override
public void onClick(final View v) { public void onClick(final View v) {
EthereumApplication app = (EthereumApplication)getActivity().getApplication();
switch(v.getId()){ switch(v.getId()){
case R.id.connectButton: case R.id.connectButton:
//app.ethereum.connect(CONFIG.activePeerIP(), CONFIG.activePeerPort(), CONFIG.activePeerNodeid()); EthereumApplication.ethereum.connect("192.168.122.90", 30303, "aceb348f4fd7b9b5033b1703b724970d93dbc6ee8410bdc20bc0585e668d629e542cd8ec560311fc8f4a0851c914aae8945555adee73878063dfa0078cc03e07");
break; break;
case R.id.getEthereumStatus: case R.id.getEthereumStatus:
app.ethereum.getConnectionStatus(identifier); EthereumApplication.ethereum.getConnectionStatus(identifier);
app.ethereum.getAdminInfo(identifier); EthereumApplication.ethereum.getAdminInfo(identifier);
break; break;
case R.id.getBlockchainStatus: case R.id.getBlockchainStatus:
app.ethereum.getBlockchainStatus(identifier); EthereumApplication.ethereum.getBlockchainStatus(identifier);
break; break;
} }
} }
@ -134,9 +132,8 @@ public class TestsFragment extends Fragment implements ConnectorHandler {
@Override @Override
public void onConnectorConnected() { public void onConnectorConnected() {
EthereumApplication app = (EthereumApplication)getActivity().getApplication(); EthereumApplication.ethereum.addListener(identifier, EnumSet.allOf(EventFlag.class));
app.ethereum.addListener(identifier, EnumSet.allOf(EventFlag.class)); //EthereumApplication.ethereum.connect(SystemProperties.CONFIG.activePeerIP(), SystemProperties.CONFIG.activePeerPort(), SystemProperties.CONFIG.activePeerNodeid());
//app.ethereum.connect(SystemProperties.CONFIG.activePeerIP(), SystemProperties.CONFIG.activePeerPort(), SystemProperties.CONFIG.activePeerNodeid());
} }
@Override @Override

View File

@ -64,6 +64,7 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
this.listener = listener; this.listener = listener;
this.peerServer = peerServer; this.peerServer = peerServer;
this.worldManager.setEthereum(this); this.worldManager.setEthereum(this);
getDefaultPeer();
} }
@Override @Override

View File

@ -3,7 +3,7 @@ package org.ethereum.android.di.components;
import android.content.Context; import android.content.Context;
import org.ethereum.android.di.modules.EthereumModule; import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum; import org.ethereum.android.Ethereum;
import org.ethereum.net.rlpx.discover.UDPListener; import org.ethereum.net.rlpx.discover.UDPListener;
import javax.inject.Singleton; import javax.inject.Singleton;

View File

@ -3,6 +3,7 @@ package org.ethereum.android.service;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import org.ethereum.android.service.events.EventFlag; import org.ethereum.android.service.events.EventFlag;
@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.List; import java.util.List;
@ -20,25 +22,51 @@ public class EthereumConnector extends ServiceConnector {
private static final Logger logger = LoggerFactory.getLogger("EthereumConnector"); private static final Logger logger = LoggerFactory.getLogger("EthereumConnector");
protected ArrayList<Message> messages = new ArrayList<>();
public EthereumConnector(Context context, Class serviceClass) { public EthereumConnector(Context context, Class serviceClass) {
super(context, serviceClass); super(context, serviceClass);
} }
public void init(List<String> privateKeys) { @Override
protected void onConnected() {
if (!isBound) if (messages.size() > 0) {
return; for(Message message: messages) {
sendMessage(message);
}
messages.clear();
}
}
protected void sendMessage(Message message) {
if (!isBound) {
messages.add(message);
} else {
try {
serviceMessenger.send(message);
} catch (RemoteException e) {
logger.error("Exception sending message(" + message.toString() + ") to service: " + e.getMessage());
}
}
}
protected Bundle getIdentifierBundle(String identifier) {
Bundle bundle = new Bundle();
bundle.putString("identifier", identifier);
return bundle;
}
public void init(List<String> privateKeys) {
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_INIT, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_INIT, 0, 0);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putStringArrayList("privateKeys", (ArrayList)privateKeys); data.putStringArrayList("privateKeys", (ArrayList) privateKeys);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(init) to service: " + e.getMessage());
}
} }
/** /**
@ -56,20 +84,13 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void connect(String ip, int port, String remoteId) { public void connect(String ip, int port, String remoteId) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_CONNECT, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_CONNECT, 0, 0);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putString("ip", ip); data.putString("ip", ip);
data.putInt("port", port); data.putInt("port", port);
data.putString("remoteId", remoteId); data.putString("remoteId", remoteId);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(connect) to service: " + e.getMessage());
}
} }
/** /**
@ -83,18 +104,11 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void loadBlocks(String dumpFile) { public void loadBlocks(String dumpFile) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_LOAD_BLOCKS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_LOAD_BLOCKS, 0, 0);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putString("dumpFile", dumpFile); data.putString("dumpFile", dumpFile);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(loadBlocks) to service: " + e.getMessage());
}
} }
/** /**
@ -104,15 +118,8 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void startJsonRpc() { public void startJsonRpc() {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_START_JSON_RPC_SERVER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_START_JSON_RPC_SERVER, 0, 0);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(startJsonRpc) to service: " + e.getMessage());
}
} }
/** /**
@ -123,17 +130,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void findOnlinePeer(String identifier) { public void findOnlinePeer(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(findOnlinePeer1) to service: " + e.getMessage());
}
} }
/** /**
@ -148,20 +148,13 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void findOnlinePeer(String identifier, PeerInfo excludePeer) { public void findOnlinePeer(String identifier, PeerInfo excludePeer) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putParcelable("excludePeer", (org.ethereum.android.interop.PeerInfo) excludePeer); data.putParcelable("excludePeer", (org.ethereum.android.interop.PeerInfo) excludePeer);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(findOnlinePeer2) to service: " + e.getMessage());
}
} }
/** /**
@ -176,20 +169,13 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void findOnlinePeer(String identifier, PeerInfo[] excludePeerSet) { public void findOnlinePeer(String identifier, PeerInfo[] excludePeerSet) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_FIND_ONLINE_PEER, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putParcelableArray("excludePeerSet", (org.ethereum.android.interop.PeerInfo[]) excludePeerSet); data.putParcelableArray("excludePeerSet", (org.ethereum.android.interop.PeerInfo[]) excludePeerSet);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(findOnlinePeer3) to service: " + e.getMessage());
}
} }
/** /**
@ -200,17 +186,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void getPeers(String identifier) { public void getPeers(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_PEERS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_PEERS, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(getPeers) to service: " + e.getMessage());
}
} }
/** /**
@ -220,15 +199,8 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void startPeerDiscovery() { public void startPeerDiscovery() {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_START_PEER_DISCOVERY, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_START_PEER_DISCOVERY, 0, 0);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(startPeerDiscovery) to service: " + e.getMessage());
}
} }
/** /**
@ -238,24 +210,9 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void stopPeerDiscovery() { public void stopPeerDiscovery() {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_LOAD_BLOCKS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_LOAD_BLOCKS, 0, 0);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(stopPeerDiscovery) to service: " + e.getMessage());
} }
}
protected Bundle getIdentifierBundle(String identifier) {
Bundle bundle = new Bundle();
bundle.putString("identifier", identifier);
return bundle;
}
/** /**
* Gets the blockchain status * Gets the blockchain status
@ -265,17 +222,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void getBlockchainStatus(String identifier) { public void getBlockchainStatus(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_BLOCKCHAIN_STATUS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_BLOCKCHAIN_STATUS, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(getBlockchainStatus) to service: " + e.getMessage());
}
} }
/** /**
@ -289,20 +239,13 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void addListener(String identifier, EnumSet<EventFlag> flags) { public void addListener(String identifier, EnumSet<EventFlag> flags) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_ADD_LISTENER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_ADD_LISTENER, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putSerializable("flags", flags); data.putSerializable("flags", flags);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(addListener) to service: " + e.getMessage());
}
} }
/** /**
@ -313,17 +256,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void removeListener(String identifier) { public void removeListener(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_REMOVE_LISTENER, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_REMOVE_LISTENER, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(addListener) to service: " + e.getMessage());
}
} }
@ -334,15 +270,8 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void closeEthereum() { public void closeEthereum() {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_CLOSE, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_CLOSE, 0, 0);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(closeEthereum) to service: " + e.getMessage());
}
} }
/** /**
@ -353,17 +282,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void getConnectionStatus(String identifier) { public void getConnectionStatus(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_CONNECTION_STATUS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_CONNECTION_STATUS, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(getConnectionStatus) to service: " + e.getMessage());
}
} }
/** /**
@ -378,20 +300,13 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void submitTransaction(String identifier, Transaction transaction) { public void submitTransaction(String identifier, Transaction transaction) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_SUBMIT_TRANSACTION, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_SUBMIT_TRANSACTION, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putParcelable("transaction", (org.ethereum.android.interop.Transaction)transaction); data.putParcelable("transaction", (org.ethereum.android.interop.Transaction)transaction);
msg.setData(data); msg.setData(data);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(submitTransaction) to service: " + e.getMessage());
}
} }
/** /**
@ -402,17 +317,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void getAdminInfo(String identifier) { public void getAdminInfo(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_ADMIN_INFO, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_ADMIN_INFO, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(getAdminInfo) to service: " + e.getMessage());
}
} }
/** /**
@ -423,17 +331,10 @@ public class EthereumConnector extends ServiceConnector {
*/ */
public void getPendingTransactions(String identifier) { public void getPendingTransactions(String identifier) {
if (!isBound)
return;
Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_PENDING_TRANSACTIONS, 0, 0); Message msg = Message.obtain(null, EthereumServiceMessage.MSG_GET_PENDING_TRANSACTIONS, 0, 0);
msg.replyTo = clientMessenger; msg.replyTo = clientMessenger;
msg.obj = getIdentifierBundle(identifier); msg.obj = getIdentifierBundle(identifier);
try { sendMessage(msg);
serviceMessenger.send(msg);
} catch (RemoteException e) {
logger.error("Exception sending message(getPendingTransactions) to service: " + e.getMessage());
}
} }
} }

View File

@ -112,9 +112,7 @@ public class EthereumRemoteService extends EthereumService {
for (String identifier: listeners) { for (String identifier: listeners) {
Messenger listener = clientListeners.get(identifier); Messenger listener = clientListeners.get(identifier);
if (listener != null) { if (listener != null) {
if (message == null) {
message = createEventMessage(event, data); message = createEventMessage(event, data);
}
message.obj = getIdentifierBundle(identifier); message.obj = getIdentifierBundle(identifier);
try { try {
listener.send(message); listener.send(message);
@ -228,7 +226,19 @@ public class EthereumRemoteService extends EthereumService {
} }
@Override @Override
protected Ethereum initializeEthereum() { protected void onEthereumCreated(List<String> privateKeys) {
if (ethereum != null) {
ethereum.init(privateKeys);
startJsonRpc(null);
broadcastEvent(EventFlag.EVENT_SYNC_DONE, new EventData());
isEthereumStarted = true;
isInitialized = true;
}
}
@Override
protected void createEthereum() {
System.setProperty("sun.arch.data.model", "32"); System.setProperty("sun.arch.data.model", "32");
System.setProperty("leveldb.mmap", "false"); System.setProperty("leveldb.mmap", "false");
@ -248,16 +258,9 @@ public class EthereumRemoteService extends EthereumService {
component = DaggerEthereumComponent.builder() component = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule(this)) .ethereumModule(new EthereumModule(this))
.build(); .build();
component.udpListener();
ethereum = component.ethereum(); ethereum = component.ethereum();
ethereum.addListener(new EthereumListener()); ethereum.addListener(new EthereumListener());
ethereum.init();
//ethereum.getDefaultPeer();
//component.udpListener();
startJsonRpc(null);
broadcastEvent(EventFlag.EVENT_SYNC_DONE, new EventData());
return null;
} }
protected void init(Message message) { protected void init(Message message) {
@ -267,12 +270,10 @@ public class EthereumRemoteService extends EthereumService {
ethereum = null; ethereum = null;
component = null; component = null;
isInitialized = false; isInitialized = false;
initializeEthereum();
} }
Bundle data = message.getData(); Bundle data = message.getData();
List<String> privateKeys = data.getStringArrayList("privateKeys"); List<String> privateKeys = data.getStringArrayList("privateKeys");
ethereum.init(); new InitializeTask(privateKeys).execute();
isEthereumStarted = true;
} }
/** /**
@ -289,7 +290,7 @@ public class EthereumRemoteService extends EthereumService {
protected void connect(Message message) { protected void connect(Message message) {
if (!isConnected) { if (!isConnected) {
isConnected = true; //isConnected = true;
new ConnectTask(message).execute(ethereum); new ConnectTask(message).execute(ethereum);
} }
} }
@ -311,7 +312,11 @@ public class EthereumRemoteService extends EthereumService {
protected Void doInBackground(Ethereum... args) { protected Void doInBackground(Ethereum... args) {
Ethereum ethereum = args[0]; Ethereum ethereum = args[0];
try {
ethereum.connect(ip, port, remoteId); ethereum.connect(ip, port, remoteId);
} catch(Exception e) {
System.out.println(e.getMessage());
}
logger.info("Ethereum connecting to : " + ip + ":" + port); logger.info("Ethereum connecting to : " + ip + ":" + port);
return null; return null;
} }

View File

@ -3,10 +3,9 @@ package org.ethereum.android.service;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message;
import org.spongycastle.util.encoders.Hex;
import org.ethereum.android.di.components.DaggerEthereumComponent; import org.ethereum.android.di.components.DaggerEthereumComponent;
import org.ethereum.android.di.components.EthereumComponent; import org.ethereum.android.di.components.EthereumComponent;
import org.ethereum.android.di.modules.EthereumModule; import org.ethereum.android.di.modules.EthereumModule;
@ -19,11 +18,11 @@ import org.ethereum.android.service.events.PeerDisconnectEventData;
import org.ethereum.android.service.events.PendingTransactionsEventData; import org.ethereum.android.service.events.PendingTransactionsEventData;
import org.ethereum.android.service.events.TraceEventData; import org.ethereum.android.service.events.TraceEventData;
import org.ethereum.android.service.events.VMTraceCreatedEventData; import org.ethereum.android.service.events.VMTraceCreatedEventData;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Genesis; import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt; import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum; import org.ethereum.android.Ethereum;
import org.ethereum.crypto.HashUtil;
import org.ethereum.net.eth.StatusMessage; import org.ethereum.net.eth.StatusMessage;
import org.ethereum.net.p2p.HelloMessage; import org.ethereum.net.p2p.HelloMessage;
import org.ethereum.net.rlpx.Node; import org.ethereum.net.rlpx.Node;
@ -60,7 +59,7 @@ public class EthereumService extends Service {
super.onCreate(); super.onCreate();
if (!isInitialized) { if (!isInitialized) {
isInitialized = true; isInitialized = true;
new InitializeTask().execute(ethereum); new InitializeTask(null).execute();
} else { } else {
System.out.println(" Already initialized"); System.out.println(" Already initialized");
System.out.println("x " + (ethereum != null)); System.out.println("x " + (ethereum != null));
@ -76,26 +75,44 @@ public class EthereumService extends Service {
ethereum.close(); ethereum.close();
} }
protected class InitializeTask extends AsyncTask<Ethereum, Message, Ethereum> { protected class InitializeTask extends AsyncTask<Void, Void, Void> {
public InitializeTask() { protected List<String> privateKeys = null;
public InitializeTask(List<String> privateKeys) {
this.privateKeys = privateKeys;
} }
protected Ethereum doInBackground(Ethereum... args) { protected Void doInBackground(Void... args) {
return initializeEthereum(); createEthereum();
return null;
} }
protected void onPostExecute(Ethereum results) { protected void onPostExecute(Void results) {
if (results != null) { onEthereumCreated(privateKeys);
EthereumService.ethereum = results;
}
} }
} }
protected Ethereum initializeEthereum() { protected void onEthereumCreated(List<String> privateKeys) {
if (ethereum != null) {
if (privateKeys == null || privateKeys.size() == 0) {
byte[] cowAddr = HashUtil.sha3("cow".getBytes());
privateKeys.add(Hex.toHexString(cowAddr));
String secret = CONFIG.coinbaseSecret();
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
privateKeys.add(Hex.toHexString(cbAddr));
}
ethereum.init(privateKeys);
broadcastEvent(EventFlag.EVENT_SYNC_DONE, new EventData());
}
}
protected void createEthereum() {
Ethereum ethereum = null; Ethereum ethereum = null;
@ -119,9 +136,6 @@ public class EthereumService extends Service {
.build(); .build();
ethereum = component.ethereum(); ethereum = component.ethereum();
ethereum.addListener(new EthereumListener()); ethereum.addListener(new EthereumListener());
ethereum.init();
return ethereum;
} }
@Override @Override

View File

@ -56,12 +56,16 @@ public class ServiceConnector {
public void handleMessage(Message message) { public void handleMessage(Message message) {
boolean isClaimed = false; boolean isClaimed = false;
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAA");
String identifier = ((Bundle)message.obj).getString("identifier"); String identifier = ((Bundle)message.obj).getString("identifier");
if (identifier != null) { if (identifier != null) {
for (ConnectorHandler handler : handlers) { for (ConnectorHandler handler : handlers) {
if (identifier.equals(handler.getID())) { if (identifier.equals(handler.getID())) {
isClaimed = handler.handleMessage(message); isClaimed = handler.handleMessage(message);
if (isClaimed) {
break;
}
} }
} }
} }
@ -88,6 +92,7 @@ public class ServiceConnector {
for (ConnectorHandler handler: handlers) { for (ConnectorHandler handler: handlers) {
handler.onConnectorConnected(); handler.onConnectorConnected();
} }
onConnected();
} }
public void onServiceDisconnected(ComponentName className) { public void onServiceDisconnected(ComponentName className) {
@ -102,6 +107,10 @@ public class ServiceConnector {
} }
}; };
protected void onConnected() {
}
public ServiceConnector(Context context, Class serviceClass) { public ServiceConnector(Context context, Class serviceClass) {
this.context = context; this.context = context;

View File

@ -32,11 +32,13 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import static java.lang.Runtime.getRuntime; import static java.lang.Runtime.getRuntime;
import static java.math.BigInteger.ZERO;
import static org.ethereum.config.Constants.*; import static org.ethereum.config.Constants.*;
import static org.ethereum.config.SystemProperties.CONFIG; import static org.ethereum.config.SystemProperties.CONFIG;
import static org.ethereum.core.Denomination.SZABO; import static org.ethereum.core.Denomination.SZABO;
import static org.ethereum.core.ImportResult.*; import static org.ethereum.core.ImportResult.*;
import static org.ethereum.util.BIUtil.isMoreThan; import static org.ethereum.util.BIUtil.isMoreThan;
import static org.ethereum.util.BIUtil.toBI;
/** /**
* The Ethereum blockchain is in many ways similar to the Bitcoin blockchain, * The Ethereum blockchain is in many ways similar to the Bitcoin blockchain,
@ -86,7 +88,7 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai
private BlockStore blockStore; private BlockStore blockStore;
private Block bestBlock; private Block bestBlock;
private BigInteger totalDifficulty = BigInteger.ZERO; private BigInteger totalDifficulty = ZERO;
Wallet wallet; Wallet wallet;
@ -250,14 +252,14 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai
// The simple case got the block // The simple case got the block
// to connect to the main chain // to connect to the main chain
if (bestBlock.isParentOf(block)) { if (bestBlock.isParentOf(block)) {
add(block);
recordBlock(block); recordBlock(block);
add(block);
return IMPORTED_BEST; return IMPORTED_BEST;
} else { } else {
if (blockStore.isBlockExist(block.getParentHash())) { if (blockStore.isBlockExist(block.getParentHash())) {
recordBlock(block);
ImportResult result = tryConnectAndFork(block); ImportResult result = tryConnectAndFork(block);
if (result == IMPORTED_BEST || result == IMPORTED_NOT_BEST) recordBlock(block);
return result; return result;
} }
@ -650,7 +652,7 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai
adminInfo.lostConsensus(); adminInfo.lostConsensus();
System.out.println("CONFLICT: BLOCK #" + block.getNumber() ); System.out.println("CONFLICT: BLOCK #" + block.getNumber() );
// System.exit(1); System.exit(1);
// in case of rollback hard move the root // in case of rollback hard move the root
// Block parentBlock = blockStore.getBlockByHash(block.getParentHash()); // Block parentBlock = blockStore.getBlockByHash(block.getParentHash());
// repository.syncToRoot(parentBlock.getStateRoot()); // repository.syncToRoot(parentBlock.getStateRoot());
@ -722,17 +724,9 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai
if (!CONFIG.recordBlocks()) return; if (!CONFIG.recordBlocks()) return;
if (block.getNumber() == 1) { String dumpDir = CONFIG.databaseDir() + "/" + CONFIG.dumpDir();
try {
FileUtils.forceDelete(new File(CONFIG.dumpDir()));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
String dir = CONFIG.dumpDir() + "/"; File dumpFile = new File(dumpDir + "/blocks-rec.dmp");
File dumpFile = new File(System.getProperty("user.dir") + "/" + dir + "_blocks_rec.txt");
FileWriter fw = null; FileWriter fw = null;
BufferedWriter bw = null; BufferedWriter bw = null;
@ -776,7 +770,18 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai
long number = bestBlock.getNumber(); long number = bestBlock.getNumber();
for (Transaction tx : transactions) { for (Transaction tx : transactions) {
BigInteger txNonce = toBI(tx.getNonce());
if (repository.isExist(tx.getSender())){
BigInteger currNonce = repository.getAccountState(tx.getSender()).getNonce();
if (currNonce.equals(txNonce))
pendingTransactions.add(new PendingTransaction(tx, number)); pendingTransactions.add(new PendingTransaction(tx, number));
} else {
if (txNonce.equals(ZERO))
pendingTransactions.add(new PendingTransaction(tx, number));
}
} }
} }

View File

@ -10,8 +10,11 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.inject.Singleton;
import static java.lang.System.getProperty; import static java.lang.System.getProperty;
@Singleton
public class MapDBFactoryImpl implements MapDBFactory { public class MapDBFactoryImpl implements MapDBFactory {
@Override @Override

View File

@ -96,6 +96,7 @@ public class WorldManager {
} }
public void setEthereum(Ethereum ethereum) { public void setEthereum(Ethereum ethereum) {
this.syncManager.setEthereum(ethereum); this.syncManager.setEthereum(ethereum);
} }

View File

@ -35,7 +35,7 @@ public class BlockHashesMessage extends EthMessage {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0); RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
blockHashes = new ArrayList<>(); blockHashes = new ArrayList<>();
for (int i = 1; i < paramsList.size(); ++i) { for (int i = 0; i < paramsList.size(); ++i) {
RLPItem rlpData = ((RLPItem) paramsList.get(i)); RLPItem rlpData = ((RLPItem) paramsList.get(i));
blockHashes.add(rlpData.getRLPData()); blockHashes.add(rlpData.getRLPData());
} }

View File

@ -157,6 +157,10 @@ public class SyncManager {
} }
} }
); );
for (Node node : CONFIG.peerActive()) {
initiateConnection(node);
}
} }
public void setBlockChain(Blockchain blockchain) { public void setBlockChain(Blockchain blockchain) {

View File

@ -3,6 +3,7 @@ package org.ethereum.net.rlpx.discover;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.ethereum.config.SystemProperties; import org.ethereum.config.SystemProperties;
import org.ethereum.manager.WorldManager; import org.ethereum.manager.WorldManager;
import org.ethereum.net.client.PeerClient;
import org.ethereum.net.rlpx.Node; import org.ethereum.net.rlpx.Node;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -60,8 +61,11 @@ public class PeerConnectionTester {
nodeHandler.getNodeStatistics().rlpxConnectionAttempts.add(); nodeHandler.getNodeStatistics().rlpxConnectionAttempts.add();
logger.debug("Trying node connection: " + nodeHandler); logger.debug("Trying node connection: " + nodeHandler);
Node node = nodeHandler.getNode(); Node node = nodeHandler.getNode();
worldManager.getActivePeer().connect(node.getHost(), node.getPort(), PeerClient activePeer = worldManager.getActivePeer();
if (activePeer != null) {
activePeer.connect(node.getHost(), node.getPort(),
new String(Hex.encodeHex(node.getId())), true); new String(Hex.encodeHex(node.getId())), true);
}
logger.debug("Terminated node connection: " + nodeHandler); logger.debug("Terminated node connection: " + nodeHandler);
nodeHandler.getNodeStatistics().disconnected(); nodeHandler.getNodeStatistics().disconnected();
if (!nodeHandler.getNodeStatistics().getEthTotalDifficulty().equals(BigInteger.ZERO) && if (!nodeHandler.getNodeStatistics().getEthTotalDifficulty().equals(BigInteger.ZERO) &&

View File

@ -19,6 +19,7 @@ peer.discovery = {
ip.list = [ ip.list = [
"54.94.239.50:30303", "54.94.239.50:30303",
"52.16.188.185:30303", "52.16.188.185:30303",
"139.162.13.89:30303"
] ]
# indicates if the discovered nodes and their reputations # indicates if the discovered nodes and their reputations
@ -39,6 +40,11 @@ peer {
# Boot node list # Boot node list
active = [ active = [
{
ip: "192.168.122.90",
port: 30303,
nodeId: "aceb348f4fd7b9b5033b1703b724970d93dbc6ee8410bdc20bc0585e668d629e542cd8ec560311fc8f4a0851c914aae8945555adee73878063dfa0078cc03e07"
}
] ]
# The protocols supported by peer # The protocols supported by peer

View File

@ -6,7 +6,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n
log4j.appender.stdout.Threshold=ERROR log4j.appender.stdout.Threshold=INFO
log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout=org.apache.log4j.PatternLayout
@ -15,22 +15,22 @@ log4j.appender.file.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolic
log4j.appender.file.RollingPolicy.FileNamePattern=./logs/ethereum_%d{yyyy-MM-dd}_h%d{HH}.log log4j.appender.file.RollingPolicy.FileNamePattern=./logs/ethereum_%d{yyyy-MM-dd}_h%d{HH}.log
# filter noisy classes # filter noisy classes
log4j.logger.org.ethereum.core = ERROR log4j.logger.org.ethereum.core = INFO
log4j.logger.org.ethereum.net = ERROR log4j.logger.org.ethereum.net = INFO
log4j.logger.org.ethereum.db = ERROR log4j.logger.org.ethereum.db = INFO
log4j.logger.peerdiscovery = ERROR log4j.logger.peerdiscovery = INFO
log4j.logger.java.nio = ERROR log4j.logger.java.nio = INFO
log4j.logger.io.netty = ERROR log4j.logger.io.netty = INFO
log4j.logger.wire = ERROR log4j.logger.wire = INFO
log4j.logger.wallet = ERROR log4j.logger.wallet = INFO
log4j.logger.VM = TRACE log4j.logger.VM = INFO
log4j.logger.dump = OFF log4j.logger.dump = OFF
log4j.logger.main = INFO log4j.logger.main = INFO
log4j.logger.trie = ERROR log4j.logger.trie = INFO
log4j.logger.state = DEBUG log4j.logger.state = INFO
log4j.logger.repository = INFO log4j.logger.repository = INFO
log4j.logger.blockchain = INFO log4j.logger.blockchain = INFO
log4j.logger.ui = ERROR log4j.logger.ui = INFO
log4j.logger.txs = ERROR log4j.logger.txs = INFO
log4j.logger.gas = ERROR log4j.logger.gas = INFO

View File

@ -16,35 +16,35 @@ log4j.appender.file.RollingPolicy.FileNamePattern=./logs/ethereum_%d{yyyy-MM-dd}
log4j.appender.file.Threshold=TRACE log4j.appender.file.Threshold=TRACE
# filter noisy classes # filter noisy classes
log4j.logger.block = ERROR log4j.logger.block = INFO
log4j.logger.blockqueue = INFO log4j.logger.blockqueue = INFO
log4j.logger.wallet = ERROR log4j.logger.wallet = INFO
log4j.logger.general = INFO log4j.logger.general = INFO
log4j.logger.net = ERROR log4j.logger.net = INFO
log4j.logger.db = ERROR log4j.logger.db = INFO
log4j.logger.peerdiscovery = ERROR log4j.logger.peerdiscovery = INFO
log4j.logger.discover = INFO log4j.logger.discover = INFO
log4j.logger.peermonitor = ERROR log4j.logger.peermonitor = INFO
log4j.logger.java.nio = ERROR log4j.logger.java.nio = INFO
log4j.logger.io.netty = ERROR log4j.logger.io.netty = INFO
log4j.logger.wire = ERROR log4j.logger.wire = INFO
log4j.logger.VM = ERROR log4j.logger.VM = INFO
log4j.logger.main = ERROR log4j.logger.main = INFO
log4j.logger.trie = ERROR log4j.logger.trie = INFO
log4j.logger.state = ERROR log4j.logger.state = INFO
log4j.logger.repository = ERROR log4j.logger.repository = INFO
log4j.logger.blockchain = ERROR log4j.logger.blockchain = INFO
log4j.logger.txs = ERROR log4j.logger.txs = INFO
log4j.logger.ui = ERROR log4j.logger.ui = INFO
log4j.logger.gas = ERROR log4j.logger.gas = INFO
log4j.logger.cli = ERROR log4j.logger.cli = INFO
log4j.logger.TCK-Test = ERROR log4j.logger.TCK-Test = INFO
log4j.logger.execute = ERROR log4j.logger.execute = INFO
log4j.logger.rlp = ERROR log4j.logger.rlp = INFO
log4j.logger.sync = INFO log4j.logger.sync = INFO
log4j.logger.org.springframework = ERROR log4j.logger.org.springframework = INFO
log4j.logger.org.hibernate = ERROR log4j.logger.org.hibernate = INFO
log4j.logger.hsqldb.db = ERROR log4j.logger.hsqldb.db = INFO