Browse Source

Peer management updates, saving peers in conf file, sortable table auto add coin, added save conf files and max peers setting in in setting tab

release/v0.1
vineetbhargav86 9 years ago
parent
commit
2708439aeb
  1. 0
      help/.tmpmarker
  2. 2
      iguana/app/coin_mgmt.js
  3. 30
      iguana/app/startup.js
  4. 42
      iguana/example.js
  5. 15
      iguana/index.html
  6. 4
      iguana/js/api.js
  7. 5
      iguana/js/jquery.tablesorter.min.js
  8. 223
      iguana/js/peerlist.js
  9. 43
      iguana/js/settings.js
  10. 2
      iguana/js/util.js

0
help/.tmpmarker

2
iguana/app/coin_mgmt.js

@ -369,7 +369,7 @@ var startCoin = function (id) {
var addExistingCoin = function (id) { var addExistingCoin = function (id) {
var isactive=0; var isactive=0;
var maxpeers=16; var maxpeers=SPNAPI.settings.maxpeers;
var services=128; var services=128;
var index = coinManagement.GetCoinIndex(id); var index = coinManagement.GetCoinIndex(id);
console.log('# coin add called '+index); console.log('# coin add called '+index);

30
iguana/app/startup.js

@ -20,15 +20,15 @@ $(function () {
pauseCoin(e.getAttribute('data-id')); pauseCoin(e.getAttribute('data-id'));
} }
else if (e.className && e.className.indexOf('addPeerToFav') != -1) { else if (e.className && e.className.indexOf('addPeerToFav') != -1) {
addPeerToFav(e.getAttribute('data-id'),e.getAttribute('data-coin')); update_favourite(e.getAttribute('data-coin'),e.getAttribute('data-ip'),e.getAttribute('data-id'),true);
} }
else if (e.className && e.className.indexOf('removePeerFromFav') != -1) { else if (e.className && e.className.indexOf('removePeerFromFav') != -1) {
removePeerFromFav(e.getAttribute('data-id'),e.getAttribute('data-coin')); update_favourite(e.getAttribute('data-coin'),e.getAttribute('data-ip'),e.getAttribute('data-id'),false);
}else if(e.className && e.className.indexOf('disconnectPeer') != -1){ }else if(e.className && e.className.indexOf('disconnectPeer') != -1){
disconnectPeer(e.getAttribute('data-ip'),e.getAttribute('data-coin')); disconnectPeer(e.getAttribute('data-ip'),e.getAttribute('data-coin'),e.getAttribute('data-id'));
}else if(e.className && e.className.indexOf('connectPeer') != -1){ }else if(e.className && e.className.indexOf('connectPeer') != -1){
connectPeer(e.getAttribute('data-ip'),e.getAttribute('data-coin')); connectPeer(e.getAttribute('data-ip'),e.getAttribute('data-coin'),e.getAttribute('data-id'));
}else if(e.className && e.className.indexOf('coinRPCactive') != -1){ }else if(e.className && e.className.indexOf('coinRPCactive') != -1){
callBlockEXPRPC(e.getAttribute('data-value')); callBlockEXPRPC(e.getAttribute('data-value'));
@ -137,14 +137,32 @@ $(function () {
InstantDEX_allpairs(); InstantDEX_allpairs();
} }
//
else if(e.className && e.className.indexOf('saveConfFiles_onclick') != -1){
reset_conf_files();
}
else if(e.className && e.className.indexOf('connect_to_peers_from_conf') != -1){
load_peers_from_conf();
}
else if(e.className && e.className.indexOf('update_allpeer_status') != -1){
update_allpeer_status();
}
else if(e.className && e.className.indexOf('save_peersdata_to_conf') != -1){
save_peersdata_to_conf();
}
}; };
$("div .btn-primary").on("click",function(){ $("div .btn-primary").on("click",function(){
$("div .btn-primary").each(function(){ $("div .btn-primary").each(function(){
$(this).removeClass('btn-raised'); $(this).removeClass('btn-raised');
}); });
$(this).addClass("btn-raised"); if(! $(this).hasClass( "_not_pressed" )){
$(this).addClass("btn-raised");}
}); });
}); });

42
iguana/example.js

@ -25,7 +25,8 @@ function errorHandler(e,callback,name) {
break; break;
case FileError.NOT_FOUND_ERR: case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR'; msg = 'NOT_FOUND_ERR';
callback(name); if(callback){
callback(name);}
break; break;
case FileError.SECURITY_ERR: case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR'; msg = 'SECURITY_ERR';
@ -74,7 +75,7 @@ var check_files=function(){
for(var j=0;j<files.length;j++){ for(var j=0;j<files.length;j++){
var name="confs/"+coins[i]+files[j]; var name="confs/"+coins[i]+files[j];
console.log("checking file "+name); console.log("checking file "+name);
files[name]=null;
check_if_file_present(name); check_if_file_present(name);
} }
} }
@ -82,6 +83,7 @@ var check_files=function(){
}; };
var check_if_file_present=function(filename,callback){ var check_if_file_present=function(filename,callback){
var contents="";
fileSystem.root.getFile(filename, {}, function(fileEntry) { fileSystem.root.getFile(filename, {}, function(fileEntry) {
//console.log("entered file fu"); //console.log("entered file fu");
// Get a File object representing the file, // Get a File object representing the file,
@ -93,7 +95,7 @@ var check_if_file_present=function(filename,callback){
//var txtArea = document.createElement('textarea'); //var txtArea = document.createElement('textarea');
//console.log("Configuration file text: "+this.result.toString()); //console.log("Configuration file text: "+this.result.toString());
console.log("File already present in HTML5 system:"+fileEntry.fullPath); console.log("File already present in HTML5 system:"+fileEntry.fullPath);
//SPNAPI.conf_files[filename]=this.result.toString(); //SPNAPI.conf_files[filename]=this.result.toString();
}; };
reader.readAsText(file); reader.readAsText(file);
@ -131,7 +133,7 @@ var save_contents=function(contents,name){
fileEntry.createWriter(function(fileWriter) { fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) { fileWriter.onwriteend = function(e) {
console.log('Write completed.'); console.log(name+' saved!');
}; };
fileWriter.onerror = function(e) { fileWriter.onerror = function(e) {
@ -148,6 +150,30 @@ var save_contents=function(contents,name){
}, errorHandler); }, errorHandler);
}; };
var delete_file=function(name){
fileSystem.root.getFile(name, {create: false}, function(fileEntry) {
fileEntry.remove(function() {
console.log(name+' removed.');
}, errorHandler);
}, errorHandler);
};
var reset_conf_files=function(){
var coins= coinManagement.getCoinSymbols();
var files=["_hdrs.txt","_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];
delete_file(name);
access_and_save_conf_file(name);
}
}
};
// Called by the common.js module. // Called by the common.js module.
function attachListeners() { function attachListeners() {
var radioEls = document.querySelectorAll('input[type="radio"]'); var radioEls = document.querySelectorAll('input[type="radio"]');
@ -289,10 +315,13 @@ var check_if_pexe_7778_working=function(string){
if(string.indexOf("iguana_rpcloop")>-1 && string.indexOf("bind sock")>-1 ){ if(string.indexOf("iguana_rpcloop")>-1 && string.indexOf("bind sock")>-1 ){
APPLICATION.port7778="successfully binded"; APPLICATION.port7778="successfully binded";
setTimeout(initialization_commands,3000);
if_changed=1; if_changed=1;
}else if(string.indexOf("finished DidCreate iguana")>-1){ }else if(string.indexOf("finished DidCreate iguana")>-1){
APPLICATION.pexe="Loaded"; APPLICATION.pexe="Loaded";
if_changed=1; if_changed=1;
setTimeout(initialization_commands,3000);
}else if(string.indexOf("ERROR BINDING PORT.7778")>-1){ }else if(string.indexOf("ERROR BINDING PORT.7778")>-1){
//APPLICATION.state="Loading.."; //APPLICATION.state="Loading..";
APPLICATION.port7778="Retrying"; APPLICATION.port7778="Retrying";
@ -324,3 +353,8 @@ var change_app_status=function(){
html=html+"<tr><td>Port 7778 state:</td><td>"+APPLICATION.port7778+"</td></tr>"; html=html+"<tr><td>Port 7778 state:</td><td>"+APPLICATION.port7778+"</td></tr>";
$("#appstatus").html(html); $("#appstatus").html(html);
}; };
var initialization_commands=function(){
addInitCoins();
};

15
iguana/index.html

@ -54,7 +54,7 @@ data-path="{tc}/{config}">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li id="welcome"> <!--<a href="#">Welcome <span class="sr-only">(current)</span></a>--></li> <li id="welcome"> <!--<a href="#">Welcome <span class="sr-only">(current)</span></a>--></li>
<li class="dropdown"> <!--<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#">Wiki</a></li> <li><a href="#">Wiki</a></li>
@ -67,7 +67,7 @@ data-path="{tc}/{config}">
<div id="byte_range"></div> <div id="byte_range"></div>
<div id="byte_content"></div> <div id="byte_content"></div>
</ul> </ul>
</li> </li>-->
</ul> </ul>
</div> </div>
<!-- /.navbar-collapse --> <!-- /.navbar-collapse -->
@ -260,6 +260,10 @@ data-path="{tc}/{config}">
</h3> </h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<button class="btn btn-xs btn-success btn-raised connect_to_peers_from_conf" >Connect to peers</button>
<button class="btn btn-xs btn-success btn-raised save_peersdata_to_conf" >Save Peers</button>
<button class="btn btn-xs btn-success btn-raised update_allpeer_status" >Update Peers</button>
<div class="pull-right"> <div class="pull-right">
<span class="checkbox"><label><input id="cbShowFavoritePeers" type="checkbox"/> Favorites</label></span> <span class="checkbox"><label><input id="cbShowFavoritePeers" type="checkbox"/> Favorites</label></span>
</div> </div>
@ -270,8 +274,10 @@ data-path="{tc}/{config}">
<th>Coin Type</th> <th>Coin Type</th>
<th>Height</th> <th>Height</th>
<th>Rank</th> <th>Rank</th>
<th>Block</th>
<th>Favourite </th> <th>Favourite </th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody id="peersTableBody"></tbody> <tbody id="peersTableBody"></tbody>
@ -329,7 +335,7 @@ data-path="{tc}/{config}">
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div class="col-xs-6 col-md-6 col-lg-6"> <div class="col-xs-6 col-md-6 col-lg-6">
<div id="agent_settings"></div> <div id="advanced_settings"></div>
</div> </div>
<div class="col-xs-6 col-md-6 col-lg-6"> <div class="col-xs-6 col-md-6 col-lg-6">
<div id="config_settings"></div> <div id="config_settings"></div>
@ -354,7 +360,7 @@ data-path="{tc}/{config}">
<div class="row"> <div class="row">
<div class="col-xs-6 col-md-6 col-lg-6"> <div class="col-xs-6 col-md-6 col-lg-6">
<div class="form-group"> <div class="form-group">
<button class="btn btn-primary" id="save_settings">Save</button> <button class="btn btn-primary _not_pressed" id="save_settings">Save</button>
</div> </div>
</div> </div>
</div> </div>
@ -538,6 +544,7 @@ data-path="{tc}/{config}">
<script type="text/javascript " src="js/instantdex.js" ></script> <script type="text/javascript " src="js/instantdex.js" ></script>
<script type="text/javascript " src="js/tradebot.js" ></script> <script type="text/javascript " src="js/tradebot.js" ></script>
<script type="text/javascript " src="js/storage.js" ></script> <script type="text/javascript " src="js/storage.js" ></script>
<script type="text/javascript " src="js/jquery.tablesorter.min.js" ></script>
</body> </body>
</html> </html>

4
iguana/js/api.js

@ -34,8 +34,8 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
SPNAPI.loadSite(page); SPNAPI.loadSite(page);
console.log(page); console.log(page);
if(page==="Peers"){ if(page==="Peers"){
peer_resonse=[]; // /peer_resonse=[];
getPeerList(); load_peers_to_pool();
}else if(page==="Settings"){ }else if(page==="Settings"){
check_files(); check_files();
//SPNAPI.check_coin_conf_files_present(); //SPNAPI.check_coin_conf_files_present();

5
iguana/js/jquery.tablesorter.min.js

File diff suppressed because one or more lines are too long

223
iguana/js/peerlist.js

@ -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) {
// // document.getElementById('peersTableBody').style.display = 'none'; favoritesOnly=document.getElementById('cbShowFavoritePeers').checked;
// // document.getElementById('peersTable_fav').style.display = 'block'; renderPeersGrid();
};
// $('#peersTableBody').hide(); var startPeerManagement = function () {
// $('#peersTable_fav').show(); renderPeersGrid();
// }
// else {
// // document.getElementById('peersTableBody').style.display = 'block'; };
// // document.getElementById('peersTable_fav').style.display = 'none';
// $('#peersTableBody').show();
// $('#peersTable_fav').hide(); var peers_pool={"connected":0,peers:[],"saved":false};
// }
favoritesOnly=document.getElementById('cbShowFavoritePeers').checked; var addpeers_from_conf= function(peer_file_as_text, coin_symbol){
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);}
}
}
}
};
var update_connected=function(coin,ip,id,value){
if(peers_pool.peers[id].ipaddr ===ip && peers_pool.peers[id].coin===coin){
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);
};

43
iguana/js/settings.js

@ -1,6 +1,6 @@
var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) { var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
SPNAPI.settings = {}; SPNAPI.settings = {maxpeers:3};
SPNAPI.conf_files={}; SPNAPI.conf_files={};
SPNAPI.getCheckBoxDetails = function(agent) { SPNAPI.getCheckBoxDetails = function(agent) {
@ -155,7 +155,39 @@ var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Use pexe or URL requests for communications</div></div>'+ '<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Use pexe or URL requests for communications</div></div>'+
'</div>'+ '</div>'+
'</div>'; '</div>';
$("#agent_settings").html(config); config += '' +
'<div class="panel panel-default">'+
'<div class="panel-body">'+
'<div class="col-xs-6 col-md-6 col-lg-6">Save default conf files</div>'+
'<div class="col-xs-6 col-md-6 col-lg-6" style="text-align: right;">' +
'<div class="checkbox">'+
'<label>'+
'<span><button class="btn btn-xs btn-success btn-raised saveConfFiles_onclick" > Save</button></span>'+
'</label>'+
'</div>' +
'</div>' +
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Save configuration files to chrome APP</div></div>'+
'</div>'+
'</div>';
config += '' +
'<div class="panel panel-default">'+
'<div class="panel-body">'+
'<div class="col-xs-6 col-md-6 col-lg-6">Maximum peers</div>'+
'<div class="col-xs-6 col-md-6 col-lg-6" style="text-align: right;">' +
'<div class="checkbox">'+
'<label>'+
'<input type="text" id="max_peers_setting" size="4" value="'+SPNAPI.settings.maxpeers+'"/>'+
'</label>'+
'</div>' +
'</div>' +
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Set number of nodes connected directly per coin type</div></div>'+
'</div>'+
'</div>';
$("#advanced_settings").html(config);
var pexe_checkbox = $('.pexe_checkbox'); var pexe_checkbox = $('.pexe_checkbox');
@ -178,6 +210,13 @@ var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
$("#save_settings").on("click", function () { $("#save_settings").on("click", function () {
//saving max peer setting
var peers=$('#max_peers_setting').val();
if(SPNAPI.settings.maxpeers!==peers){
SPNAPI.settings.maxpeers=peers;
console.log("maxpeers set to "+SPNAPI.settings.maxpeers);
}
/*var agent_checkbox = $('.agent_checkbox'); /*var agent_checkbox = $('.agent_checkbox');
var settings = []; var settings = [];

2
iguana/js/util.js

@ -131,7 +131,7 @@ function DateTime() {
}; };
}; };
document.getElementById('files').addEventListener('change', handleFileSelect, false); //document.getElementById('files').addEventListener('change', handleFileSelect, false);
function handleFileSelect(evt) { function handleFileSelect(evt) {
var startByte = evt.target.getAttribute('data-startbyte'); var startByte = evt.target.getAttribute('data-startbyte');

Loading…
Cancel
Save