elective-stereophonic
elective-stereophonic
http://nxtpeers.com
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Stable Nxt Client: Nxt 1.12.2

Author Topic: http://nxtpeers.com  (Read 3278 times)

Tosch110

  • Board Moderator
  • Hero Member
  • ****
  • Karma: +211/-18
  • Offline Offline
  • Posts: 2365
    • View Profile
http://nxtpeers.com
« 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



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 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.
« Last Edit: November 14, 2014, 01:25:47 am by Tosch110 »
Logged

verymuchso

  • Hero Member
  • *****
  • Karma: +118/-2
  • Offline Offline
  • Posts: 549
    • View Profile
    • HEAT Ledger
Re: http://nxtpeers.com
« Reply #1 on: November 13, 2014, 11:23:03 pm »

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 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
Logged
HEAT: DEX | SDK | HOME

Tosch110

  • Board Moderator
  • Hero Member
  • ****
  • Karma: +211/-18
  • Offline Offline
  • Posts: 2365
    • View Profile
Re: http://nxtpeers.com
« Reply #2 on: November 13, 2014, 11:28:16 pm »

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 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?

crimi

  • Hero Member
  • *****
  • Karma: +122/-11
  • Offline Offline
  • Posts: 863
    • View Profile
Re: http://nxtpeers.com
« Reply #3 on: November 14, 2014, 03:18:45 am »

Good to see finally some competition. Keep going.  :D
Logged

allwelder

  • Hero Member
  • *****
  • Karma: +196/-13
  • Offline Offline
  • Posts: 1867
  • NxtChina.org
    • View Profile
    • NxtChina.org
Re: http://nxtpeers.com
« Reply #4 on: November 14, 2014, 06:41:37 am »

Great.
Added on Nxt123.
Logged
NxtChina |Weibo |Twitter Donation welcomed:NXT-APL9-66GU-K8LY-B3JJJ

verymuchso

  • Hero Member
  • *****
  • Karma: +118/-2
  • Offline Offline
  • Posts: 549
    • View Profile
    • HEAT Ledger
Re: http://nxtpeers.com
« Reply #5 on: November 14, 2014, 08:59:07 am »

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 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.

Code: [Select]
# 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.


Logged
HEAT: DEX | SDK | HOME

Tosch110

  • Board Moderator
  • Hero Member
  • ****
  • Karma: +211/-18
  • Offline Offline
  • Posts: 2365
    • View Profile
Re: http://nxtpeers.com
« Reply #6 on: November 14, 2014, 07:29:28 pm »

Thanks for this, I understand the approach, will look into this at the weekend.
 

elective-stereophonic
elective-stereophonic
assembly
assembly