|
@ -46,7 +46,7 @@ function addpeer_toresponse(request, response){ |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
function connectPeer(ip,coin){ |
|
|
function connectPeer(ip,coin,id){ |
|
|
|
|
|
|
|
|
var request='{"agent":"iguana","method":"addnode","ipaddr":'+'"'+ip+'","coin":"' + coin + '"}'; |
|
|
var request='{"agent":"iguana","method":"addnode","ipaddr":'+'"'+ip+'","coin":"' + coin + '"}'; |
|
|
console.log("connection to peer:"+ip+" coin:"+coin); |
|
|
console.log("connection to peer:"+ip+" coin:"+coin); |
|
@ -54,7 +54,7 @@ function connectPeer(ip,coin){ |
|
|
//console.log('Response is ' + response);
|
|
|
//console.log('Response is ' + response);
|
|
|
var res=JSON.parse(response); |
|
|
var res=JSON.parse(response); |
|
|
if(res.result==="addnode submitted"){ |
|
|
if(res.result==="addnode submitted"){ |
|
|
addPeerToConn(ip,coin); |
|
|
update_connected(coin,ip,id,true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -66,13 +66,14 @@ function connectPeer(ip,coin){ |
|
|
* @returns {undefined} |
|
|
* @returns {undefined} |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
function disconnectPeer(ip,coin){ |
|
|
function disconnectPeer(ip,coin,id){ |
|
|
|
|
|
|
|
|
var request='{"agent":"iguana","method":"removenode","ipaddr":'+'"'+ip+'","coin":"' + coin + '"}'; |
|
|
var request='{"agent":"iguana","method":"removenode","ipaddr":'+'"'+ip+'","coin":"' + coin + '"}'; |
|
|
console.log("disconnection to peer:"+ip+" coin:"+coin); |
|
|
console.log("disconnection to peer:"+ip+" coin:"+coin); |
|
|
SPNAPI.makeRequest(request, function(request,response){ |
|
|
SPNAPI.makeRequest(request, function(request,response){ |
|
|
//console.log('Response is ' + response);
|
|
|
//console.log('Response is ' + response);
|
|
|
removePeerFromConn(ip,coin); |
|
|
// removePeerFromConn(ip,coin);
|
|
|
|
|
|
update_connected(coin,ip,id,false); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -87,29 +88,33 @@ var favPeers = []; |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
var connectedPeers=[]; |
|
|
var connectedPeers=[]; |
|
|
var getHtmlRow = function (id,coin, peer) { |
|
|
var getHtmlRow = function (peer,id) { |
|
|
|
|
|
// /var peer={"ipaddr":peers[ip],"coin":coin_symbol,"connected":false,"favourite":false,"nodestatus":{"ipaddr":peers[ip],"protover":0,"relay":0,"height":0,"rank":0,"usock":0,"ready":0,"recvblocks":0,"recvtotal":0,"lastcontact":0,"msgcounts":{"version":0,"verack":0,"getaddr":0,"addr":0,"inv":0,"getdata":0,"notfound":0,"getblocks":0,"getheaders":0,"headers":0,"tx":0,"block":0,"mempool":0,"ping":0,"pong":0,"reject":0,"filterload":0,"filteradd":0,"filterclear":0,"merkleblock":0,"alert":0}}};
|
|
|
|
|
|
|
|
|
var row = ''; |
|
|
var row = ''; |
|
|
var data=id+coin; |
|
|
var data=peer.ipaddr+peer.coin; |
|
|
row = '<tr data-id="' + data.toString() + '">'; |
|
|
row = '<tr data-id="' + data.toString() + '">'; |
|
|
row += '<td>' + peer.ipaddr + '</td>'; |
|
|
row += '<td>' + peer.ipaddr + '</td>'; |
|
|
row += '<td>' + peer.cointype + '</td>'; |
|
|
row += '<td>' + peer.coin + '</td>'; |
|
|
row += '<td>' + peer.height + '</td>'; |
|
|
row += '<td>' + peer.nodestatus.height + '</td>'; |
|
|
row += '<td>' + peer.rank + '</td>'; |
|
|
row += '<td>' + peer.nodestatus.rank + '</td>'; |
|
|
if ($.inArray(data, favPeers) === -1) { |
|
|
row += '<td>' + peer.nodestatus.msgcounts.block + '</td>'; |
|
|
row += '<td><button class="btn btn-xs btn-success btn-raised addPeerToFav" data-coin="'+peer.cointype.toString()+'" data-id="' + id.toString() + '"> + Favorite</button></td>'; |
|
|
|
|
|
|
|
|
if (!peer.favourite) { |
|
|
|
|
|
row += '<td><button class="btn btn-xs btn-success btn-raised addPeerToFav" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.coin.toString()+'" data-id="' + id.toString() + '"> + Favorite</button></td>'; |
|
|
// row += '<td><i class="material-icons addPeerToFav" data-id="' + id.toString() + '">bookmark_border</i></td>';
|
|
|
// row += '<td><i class="material-icons addPeerToFav" data-id="' + id.toString() + '">bookmark_border</i></td>';
|
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
row += '<td><button class="btn btn-xs btn-danger btn-raised removePeerFromFav" data-coin="'+peer.cointype.toString()+'" data-id="' + id.toString() + '"> - Unfavorite</button></td>'; |
|
|
row += '<td><button class="btn btn-xs btn-danger btn-raised removePeerFromFav" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.coin.toString()+'" data-id="' + id.toString() + '"> - Unfavorite</button></td>'; |
|
|
// row += '<td><i class="material-icons removePeerFromFav" data-id="' + id.toString() + '">bookmark</i></td>'
|
|
|
// row += '<td><i class="material-icons removePeerFromFav" data-id="' + id.toString() + '">bookmark</i></td>'
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($.inArray(peer.ipaddr.toString()+" "+peer.cointype.toString(), connectedPeers) === -1) { |
|
|
if (!peer.connected) { |
|
|
row += '<td><button class="btn btn-xs btn-success btn-raised connectPeer" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.cointype.toString()+'" data-id="' + id.toString() + '"> + Connect</button>'; |
|
|
row += '<td><button class="btn btn-xs btn-success btn-raised connectPeer" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.coin.toString()+'" data-id="' + id.toString() + '"> + Connect</button>'; |
|
|
row +='</td>'; |
|
|
row +='</td>'; |
|
|
|
|
|
|
|
|
}else{ |
|
|
}else{ |
|
|
row += '<td><button class="btn btn-xs btn-danger btn-raised disconnectPeer" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.cointype.toString()+'" data-id="' + id.toString() + '"> -Disconnect</button>'; |
|
|
row += '<td><button class="btn btn-xs btn-danger btn-raised disconnectPeer" data-ip="'+peer.ipaddr.toString()+'" data-coin="'+peer.coin.toString()+'" data-id="' + id.toString() + '"> -Disconnect</button>'; |
|
|
row +='</td>'; |
|
|
row +='</td>'; |
|
|
} |
|
|
} |
|
|
row += '</tr>'; |
|
|
row += '</tr>'; |
|
@ -189,46 +194,190 @@ var renderPeersGrid = function () { |
|
|
console.log('@ peer print grid'); |
|
|
console.log('@ peer print grid'); |
|
|
|
|
|
|
|
|
var peersTableAllHtml = ''; |
|
|
var peersTableAllHtml = ''; |
|
|
for(var j=0; j<peer_resonse.length;j++){ |
|
|
for(var j=0; j<peers_pool.peers.length;j++){ |
|
|
var res=peer_resonse[j]; |
|
|
var res=peers_pool.peers[j]; |
|
|
for (var i = 0; i < res.peers.length; i++) { |
|
|
// for (var i = 0; i < res.peers.length; i++) {
|
|
|
var data=i+res.coin; |
|
|
if (favoritesOnly === true && !res.favourite) { |
|
|
if (favoritesOnly === true && $.inArray(data.toString(), favPeers) === -1) { |
|
|
|
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
//console.log(data.toString());
|
|
|
//console.log(data.toString());
|
|
|
res.peers[i].cointype = res.coin; |
|
|
peersTableAllHtml += getHtmlRow(res,j); |
|
|
peersTableAllHtml += getHtmlRow(i,res.coin, res.peers[i]); |
|
|
//}
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
document.getElementById('peersTableBody').innerHTML = peersTableAllHtml; |
|
|
document.getElementById('peersTableBody').innerHTML = peersTableAllHtml; |
|
|
|
|
|
$("#peersTable").tablesorter(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('cbShowFavoritePeers').onclick = function () { |
|
|
document.getElementById('cbShowFavoritePeers').onclick = function () { |
|
|
// if (document.getElementById('cbShowFavoritePeers').checked == true) {
|
|
|
|
|
|
|
|
|
favoritesOnly=document.getElementById('cbShowFavoritePeers').checked; |
|
|
|
|
|
renderPeersGrid(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var startPeerManagement = function () { |
|
|
|
|
|
renderPeersGrid(); |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// // document.getElementById('peersTableBody').style.display = 'none';
|
|
|
|
|
|
// // document.getElementById('peersTable_fav').style.display = 'block';
|
|
|
|
|
|
|
|
|
|
|
|
// $('#peersTableBody').hide();
|
|
|
var peers_pool={"connected":0,peers:[],"saved":false}; |
|
|
// $('#peersTable_fav').show();
|
|
|
|
|
|
// }
|
|
|
var addpeers_from_conf= function(peer_file_as_text, coin_symbol){ |
|
|
// else {
|
|
|
var peers=peer_file_as_text.split("\n"); |
|
|
|
|
|
var showConnected=true; |
|
|
|
|
|
for(var ip in peers){ |
|
|
|
|
|
if(showConnected && ip<SPNAPI.settings.maxpeers){ |
|
|
|
|
|
if(peers[ip]!=="" && peers[ip]!=="\n"){ |
|
|
|
|
|
console.log(peers[ip]); |
|
|
|
|
|
var peer={"ipaddr":peers[ip],"coin":coin_symbol,"connected":false,"favourite":false,"nodestatus":{"ipaddr":peers[ip],"protover":0,"relay":0,"height":0,"rank":0,"usock":0,"ready":0,"recvblocks":0,"recvtotal":0,"lastcontact":0,"msgcounts":{"version":0,"verack":0,"getaddr":0,"addr":0,"inv":0,"getdata":0,"notfound":0,"getblocks":0,"getheaders":0,"headers":0,"tx":0,"block":0,"mempool":0,"ping":0,"pong":0,"reject":0,"filterload":0,"filteradd":0,"filterclear":0,"merkleblock":0,"alert":0}}}; |
|
|
|
|
|
peers_pool.peers.push(peer); |
|
|
|
|
|
if(ip<SPNAPI.settings.maxpeers){ |
|
|
|
|
|
connectPeer_from_conf(peers[ip],coin_symbol);} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// // document.getElementById('peersTableBody').style.display = 'block';
|
|
|
}; |
|
|
// // document.getElementById('peersTable_fav').style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
// $('#peersTableBody').show();
|
|
|
var update_connected=function(coin,ip,id,value){ |
|
|
// $('#peersTable_fav').hide();
|
|
|
|
|
|
// }
|
|
|
if(peers_pool.peers[id].ipaddr ===ip && peers_pool.peers[id].coin===coin){ |
|
|
favoritesOnly=document.getElementById('cbShowFavoritePeers').checked; |
|
|
peers_pool.peers[id].connected=value; |
|
|
|
|
|
}else{ |
|
|
|
|
|
for(var peers in peers_pool.peers){ |
|
|
|
|
|
if(peers_pool.peers[peers].ipaddr ===ip && peers_pool.peers[peers].coin===coin){ |
|
|
|
|
|
peers_pool.peers[peers].connected=value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
renderPeersGrid(); |
|
|
renderPeersGrid(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var startPeerManagement = function () { |
|
|
var update_favourite=function(coin,ip,id,value){ |
|
|
|
|
|
console.log("@update_favourite got values coin:"+coin+" ip:"+ip+" id:"+id+" value:"+value); |
|
|
|
|
|
|
|
|
|
|
|
if(peers_pool.peers[id].ipaddr ===ip && peers_pool.peers[id].coin===coin){ |
|
|
|
|
|
peers_pool.peers[id].favourite=value; |
|
|
|
|
|
}else{ |
|
|
|
|
|
for(var peers in peers_pool.peers){ |
|
|
|
|
|
if(peers_pool.peers[peers].ipaddr ===ip && peers_pool.peers[peers].coin===coin){ |
|
|
|
|
|
peers_pool.peers[peers].favourite=value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
renderPeersGrid(); |
|
|
renderPeersGrid(); |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var update_allpeer_status=function(){ |
|
|
|
|
|
for(var peers in peers_pool.peers){ |
|
|
|
|
|
if(peers_pool.peers[peers].connected=== true){ |
|
|
|
|
|
var request='{"agent":"iguana","method":"nodestatus","ipaddr":'+'"'+peers_pool.peers[peers].ipaddr+'","coin":"' + peers_pool.peers[peers].coin + '"}'; |
|
|
|
|
|
SPNAPI.makeRequest(request,function(request,response){ |
|
|
|
|
|
|
|
|
|
|
|
//console.log('Response is ' + response);
|
|
|
|
|
|
// console.log('Request was ' + JSON.parse(request));
|
|
|
|
|
|
|
|
|
|
|
|
var res=JSON.parse(response); |
|
|
|
|
|
if(res.result!=="nodestatus couldnt find ipaddr"){ |
|
|
|
|
|
peers_pool.peers[peers].nodestatus=res; |
|
|
|
|
|
renderPeersGrid(); |
|
|
|
|
|
}else{ |
|
|
|
|
|
console.log("opps! peer isnt there."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var save_peersdata_to_conf=function(){ |
|
|
|
|
|
if(peers_pool.saved){ |
|
|
|
|
|
delete_file("confs/peer_tab.save"); |
|
|
|
|
|
} |
|
|
|
|
|
save_contents(JSON.stringify(peers_pool),"confs/peer_tab.save"); |
|
|
|
|
|
peers_pool.saved=true; |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var load_peers_to_pool=function(){ |
|
|
|
|
|
|
|
|
|
|
|
fileSystem.root.getFile("confs/peer_tab.save", {}, function(fileEntry) { |
|
|
|
|
|
//console.log("entered file fu");
|
|
|
|
|
|
// Get a File object representing the file,
|
|
|
|
|
|
// then use FileReader to read its contents.
|
|
|
|
|
|
fileEntry.file(function(file) { |
|
|
|
|
|
var reader = new FileReader(); |
|
|
|
|
|
|
|
|
|
|
|
reader.onloadend = function(e) { |
|
|
|
|
|
var peer=this.result; |
|
|
|
|
|
console.log("reading peerconf file "+this.result); |
|
|
|
|
|
peers_pool=JSON.parse(peer); |
|
|
|
|
|
renderPeersGrid(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
reader.readAsText(file); |
|
|
|
|
|
}, function(e){ |
|
|
|
|
|
errorHandler(e); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, function(e){ |
|
|
|
|
|
errorHandler(e); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function connectPeer_from_conf(ip,coin){ |
|
|
|
|
|
|
|
|
|
|
|
var request='{"agent":"iguana","method":"addnode","ipaddr":'+'"'+ip+'","coin":"' + coin + '"}'; |
|
|
|
|
|
console.log("connecting to peer:"+ip+" coin:"+coin); |
|
|
|
|
|
SPNAPI.makeRequest(request,function(request,response){ |
|
|
|
|
|
//console.log('Response is ' + response);
|
|
|
|
|
|
var res=JSON.parse(response); |
|
|
|
|
|
if(res.result==="addnode submitted"){ |
|
|
|
|
|
console.log('connected to peer ' + ip+" supporting "+coin); |
|
|
|
|
|
update_connected(coin,ip,0,true); |
|
|
|
|
|
renderPeersGrid(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var load_peers_from_conf=function(){ |
|
|
|
|
|
var coins= coinManagement.getCoinSymbols(); |
|
|
|
|
|
var files=["_peers.txt"]; |
|
|
|
|
|
for(var i=0;i<coins.length;i++){ |
|
|
|
|
|
|
|
|
|
|
|
for(var j=0;j<files.length;j++){ |
|
|
|
|
|
var name="confs/"+coins[i]+files[j]; |
|
|
|
|
|
load_peer_file(name,coins[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var load_peer_file=function(name,coin){ |
|
|
|
|
|
|
|
|
|
|
|
fileSystem.root.getFile(name, {}, function(fileEntry) { |
|
|
|
|
|
|
|
|
|
|
|
// Get a File object representing the file,
|
|
|
|
|
|
// then use FileReader to read its contents.
|
|
|
|
|
|
fileEntry.file(function(file) { |
|
|
|
|
|
var reader = new FileReader(); |
|
|
|
|
|
|
|
|
|
|
|
reader.onloadend = function(e) { |
|
|
|
|
|
addpeers_from_conf(this.result,coin); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
reader.readAsText(file); |
|
|
|
|
|
}, errorHandler); |
|
|
|
|
|
|
|
|
|
|
|
}, errorHandler); |
|
|
}; |
|
|
}; |
|
|