Nxt Forum
Nxt Discussion => -Old and Inactive Projects- => Nxt Projects => NxtPeers => Topic started by: Tosch110 on November 13, 2014, 11:03:59 pm
-
Hello, I am Tosch, I am active on developing websites and applications with Nxt for some longer time now. While doing this, I have noticed that you can not connect to any sticked server to receive the data you want but you can connect from any website or device to other Nxt public nodes and start using the NXT Dataflow directly from the Blockchain. But to receive the list of nodes, you would need to be connected to the Nxt Network yourself. So I thought it might be a good idea to have a server connected to the network which displays exactly these data:
http://nxtpeers.com
(http://s14.directupload.net/images/141113/aw2zu5bp.png) (http://nxtpeers.com)
Now that we have a list of the public nodes, we could choose one of those who accepts calls from the outside (GET), which are hallmarked, have cors (javascript) enabled, a special version or whatever is needed for developing something with the Blockchain Data.
But these are public nodes maintained by other Nxter, which decided to make this available for development and public access. You cannot know, if they go offline at anytime, so I am saving them into a local database and regularly check for access. The current list is displayed on the main page.
The API
http://nxtpeers.com/api.php
With the API I am providing a stable tunnel to Nxt Server. These can be directly accessed, saved and tested locally etc. I am hoping this way people that do not have the possibility to host Nxt yet, can access the API via public nodes which they receive from the nxtpeers.com API. (example: http://nxtpeers.com/api/) If everything is working, it is recommended to switch to an own server with hosted Nxt, so calls can be made localhost. The API is just recommended to display data from the Blockchain (using GET requests).
The nxtpeers platform is still under development. If this is something which is used regularly I could initiate to get stronger server etc to get it all more comprehensive and stable.
Instead of manually inserting the node anytime yourself into your API call (or update) I have included several node accessing API's:
Last checked single node, with newest NRS version, hallmarked (good ping):
http://nxtpeers.com/api/index.php
A list of 30 nodes:
http://nxtpeers.com/api/peers.php
A list of hallmarked nodes:
http://nxtpeers.com/api/hallmark.php
Last checked single node, with newest NRS version, hallmarked, cors enabled:
http://nxtpeers.com/api/cors/
In this forum I am going to provide examples what you could do with this development kit. I have a vision where a tool like this can keep supporting the thought of decentralization and user empowerement. The peers are taken randomly from the list while preferring hallmarked and fast nodes from the network.
For easy and advanced usage
PHP
Using nxtpeers.com (http://nxtpeers.com) as development helping tool, I am providing some example scripts in this forum. The code will be open source. While I hope that people using and adjusting the script could share what they have done with it so the examples keep improving over time and are not dependend on just my time.
Since I am most familiar with accessing Nxt via PHP, I have made the first access and usage examples available in PHP.
They should work with just having PHP installed. Every feedback on this would be helpful.
http://nxtpeers.com/examples.php
See how to simple connect and make calls to Nxt via PHP:
http://nxtpeers.com/api_php.php
Every feedback is appreciated. The scripts are under development and I can need any help to optimize them.
-
Good initiative!
For mofowallet I'm looking for a way to obtain a fresh list of SSL NXT nodes for the mofo web and mixed SSL/Non-SSL nodes for mofo desktop.
Users can already add and remove public nodes in the nodes section (https://fimkrypto.github.io/mofo/launch.html#/settings/nodes) what I would like to add is an option for the user to click and download a list of public peers.
It seems non-ssl http peers are available with your service as they are with peerexplorer http://www.peerexplorer.com/api_openapi
But your API data http://nxtpeers.com/api/peers.php doesn't seem to indicate anything about SSL (https) nodes.
Other question? How do you scan for peers? Do you use the peer protocol on port 7874 to scan the entire network or just the peers that connect with your own node?
Thanks
-
Good initiative!
For mofowallet I'm looking for a way to obtain a fresh list of SSL NXT nodes for the mofo web and mixed SSL/Non-SSL nodes for mofo desktop.
Users can already add and remove public nodes in the nodes section (https://fimkrypto.github.io/mofo/launch.html#/settings/nodes) what I would like to add is an option for the user to click and download a list of public peers.
It seems non-ssl http peers are available with your service as they are with peerexplorer http://www.peerexplorer.com/api_openapi
But your API data http://nxtpeers.com/api/peers.php doesn't seem to indicate anything about SSL (https) nodes.
Other question? How do you scan for peers? Do you use the peer protocol on port 7874 to scan the entire network or just the peers that connect with your own node?
Thanks
Thanks for mentioning this, I will look to add SSL nodechecks. I am receiving the nodes via Nxt Server API:
http://localhost:7876/nxt?requestType=getPeers&active=true
Do you know a more effective method?
-
Good to see finally some competition. Keep going. :D
-
Great.
Added on Nxt123 (http://nxt123.org).
(https://i.imgur.com/ULHYfXB.jpg)
-
Good initiative!
For mofowallet I'm looking for a way to obtain a fresh list of SSL NXT nodes for the mofo web and mixed SSL/Non-SSL nodes for mofo desktop.
Users can already add and remove public nodes in the nodes section (https://fimkrypto.github.io/mofo/launch.html#/settings/nodes) what I would like to add is an option for the user to click and download a list of public peers.
It seems non-ssl http peers are available with your service as they are with peerexplorer http://www.peerexplorer.com/api_openapi
But your API data http://nxtpeers.com/api/peers.php doesn't seem to indicate anything about SSL (https) nodes.
Other question? How do you scan for peers? Do you use the peer protocol on port 7874 to scan the entire network or just the peers that connect with your own node?
Thanks
Thanks for mentioning this, I will look to add SSL nodechecks. I am receiving the nodes via Nxt Server API:
http://localhost:7876/nxt?requestType=getPeers&active=true
Do you know a more effective method?
Yes.
Use the peer protocol on port 7874 it's always open unlike the API protocol.
It's a bit tricky to get the requests right but the following code has worked for me (this is Ruby) it's not all of it just a snippet to show what I mean.
# Returns an array of ip addresses
def get_peers(ip)
peer_protocol(ip, {"requestType" => "getPeers"})['peers']
end
# Returns { cumulativeDifficulty : 1, blockchainHeight: 3 }
def get_cumulative_difficulty(ip)
peer_protocol(ip, {"requestType" => "getCumulativeDifficulty"})
end
def get_info(ip)
peer_protocol(ip, {"requestType" => "getInfo"})
end
def peer_protocol(ip, params)
begin
params['protocol'] = 1
puts ip
uri = URI.parse("http://#{ip}:#{$peer_port}/nxt")
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 10
http.ssl_timeout = 10
http.read_timeout = 10
http.continue_timeout = 10
http.keep_alive_timeout = 10
request = Net::HTTP::Post.new(uri.request_uri)
#request.read_timeout = 10000
request.body = params.to_json
request.content_type = 'multipart/form-data'
response = http.request(request)
puts "POST #{ip} #{params['requestType']} => #{response.body}"
JSON.parse response.body
rescue => msg
{ error: msg.to_s }
end
end
# Look through the peers dict for a peer that has no connected peers
def get_next_peer
$peers.keys.detect { |ip| $peers[ip]['connected_peers'].nil? }
end
def scan_network_for_peers
ip = get_next_peer
puts "Found this ip #{ip}"
while ip do
# Ask peer for connected peers
connected_peers = get_peers(ip) || []
connected_peers.each { |_ip| $peers[_ip] = {} unless $peers.has_key? _ip }
$peers[ip]['connected_peers'] = connected_peers
# Get blockchainheight and difficulty
obj = get_cumulative_difficulty(ip)
$peers[ip]['cumulativeDifficulty'] = obj['cumulativeDifficulty']
$peers[ip]['blockchainHeight'] = obj['blockchainHeight']
# Get peer info
obj = get_info(ip)
$peers[ip]['application'] = obj['application']
$peers[ip]['version'] = obj['version']
$peers[ip]['platform'] = obj['platform']
$peers[ip]['shareAddress'] = obj['shareAddress']
ip = get_next_peer
end
end
Once you have the list of peers after calling getPeers simply call getPeers on all peers you get back and then again on all the others. Etc..
You'll end up with all the nodes in the network.
-
Thanks for this, I understand the approach, will look into this at the weekend.