Search Preview
How to handle networking/peer APIs
bitcoinj.github.ioIntroduction Getting started Documentation Community #How to handle networking/peer APIs This article applies
.io > bitcoinj.github.io
SEO audit: Content analysis
Language | Error! No language localisation is found. | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Title | How to handle networking/peer APIs | ||||||||||||||||||||||||||||||||||||
Text / HTML ratio | 47 % | ||||||||||||||||||||||||||||||||||||
Frame | Excellent! The website does not use iFrame solutions. | ||||||||||||||||||||||||||||||||||||
Flash | Excellent! The website does not have any flash contents. | ||||||||||||||||||||||||||||||||||||
Keywords cloud | Tor sockets network PeerGroup peer proxy = bitcoinj messages peers simple connect level peerGroup connections top future Peer SOCKS blocking | ||||||||||||||||||||||||||||||||||||
Keywords consistency |
|
||||||||||||||||||||||||||||||||||||
Headings | Error! The website does not use (H) tags. | ||||||||||||||||||||||||||||||||||||
Images | We found 1 images on this web page. |
SEO Keywords (Single)
Keyword | Occurrence | Density |
---|---|---|
Tor | 10 | 0.50 % |
sockets | 7 | 0.35 % |
network | 7 | 0.35 % |
PeerGroup | 6 | 0.30 % |
peer | 5 | 0.25 % |
proxy | 4 | 0.20 % |
= | 4 | 0.20 % |
bitcoinj | 4 | 0.20 % |
messages | 4 | 0.20 % |
peers | 4 | 0.20 % |
simple | 4 | 0.20 % |
connect | 4 | 0.20 % |
level | 3 | 0.15 % |
peerGroup | 3 | 0.15 % |
connections | 3 | 0.15 % |
top | 3 | 0.15 % |
future | 3 | 0.15 % |
Peer | 3 | 0.15 % |
SOCKS | 3 | 0.15 % |
blocking | 3 | 0.15 % |
SEO Keywords (Two Word)
Keyword | Occurrence | Density |
---|---|---|
to the | 6 | 0.30 % |
a PeerGroup | 4 | 0.20 % |
the network | 4 | 0.20 % |
blocking sockets | 3 | 0.15 % |
= new | 3 | 0.15 % |
peerGroup = | 3 | 0.15 % |
SOCKS proxy | 3 | 0.15 % |
to do | 3 | 0.15 % |
to use | 3 | 0.15 % |
can be | 3 | 0.15 % |
you can | 3 | 0.15 % |
sockets or | 3 | 0.15 % |
lower level | 2 | 0.10 % |
can use | 2 | 0.10 % |
use blocking | 2 | 0.10 % |
of those | 2 | 0.10 % |
chain new | 2 | 0.10 % |
like this | 2 | 0.10 % |
a simple | 2 | 0.10 % |
for each | 2 | 0.10 % |
SEO Keywords (Three Word)
Keyword | Occurrence | Density | Possible Spam |
---|---|---|---|
to the network | 3 | 0.15 % | No |
connect to the | 2 | 0.10 % | No |
On top of | 2 | 0.10 % | No |
The bitcoinj networking | 2 | 0.10 % | No |
peerGroup = new | 2 | 0.10 % | No |
blocking sockets or | 2 | 0.10 % | No |
use blocking sockets | 2 | 0.10 % | No |
top of those | 2 | 0.10 % | No |
Override public void | 2 | 0.10 % | No |
PeerGroup peerGroup = | 2 | 0.10 % | No |
a SOCKS proxy | 2 | 0.10 % | No |
you wish to | 2 | 0.10 % | No |
you can use | 2 | 0.10 % | No |
that in 012 | 1 | 0.05 % | No |
The first is | 1 | 0.05 % | No |
here The first | 1 | 0.05 % | No |
first is that | 1 | 0.05 % | No |
is that in | 1 | 0.05 % | No |
Tor support finds | 1 | 0.05 % | No |
in 012 the | 1 | 0.05 % | No |
SEO Keywords (Four Word)
Keyword | Occurrence | Density | Possible Spam |
---|---|---|---|
On top of those | 2 | 0.10 % | No |
connect to the network | 2 | 0.10 % | No |
Introduction Getting started Documentation | 1 | 0.05 % | No |
The first is that | 1 | 0.05 % | No |
There are some important | 1 | 0.05 % | No |
are some important things | 1 | 0.05 % | No |
some important things to | 1 | 0.05 % | No |
important things to note | 1 | 0.05 % | No |
things to note here | 1 | 0.05 % | No |
to note here The | 1 | 0.05 % | No |
note here The first | 1 | 0.05 % | No |
here The first is | 1 | 0.05 % | No |
is that in 012 | 1 | 0.05 % | No |
first is that in | 1 | 0.05 % | No |
do that There are | 1 | 0.05 % | No |
that in 012 the | 1 | 0.05 % | No |
in 012 the Tor | 1 | 0.05 % | No |
012 the Tor support | 1 | 0.05 % | No |
the Tor support finds | 1 | 0.05 % | No |
Tor support finds peers | 1 | 0.05 % | No |
Internal links in - bitcoinj.github.io
Building a simple GUI wallet tutorial
Which BIPs are supported by bitcoinj
How to depend on bitcoinj with Maven using projects
How to depend on bitcoinj with Gradle using projects
An introduction to using the library
bitcoinj 0.14.7 API
Limitations and missing features.
Understanding the bitcoinj security model
Working with bitcoinj
How the different components of your app fit together
How to test applications
Working with transactions
Working with the wallet
Working with monetary amounts
How to handle networking/peer APIs
API Contexts
Using the experimental full verification mode
Working with contracts
Working with the BIP70 payment protocol API
Working with micropayment channels
How to access bitcoinj from other languages
Coding conventions in bitcoinj
Release notes
Bitcoinj.github.io Spined HTML
How to handle networking/peer APIs Introduction Getting started Documentation Community #How to handle networking/peer APIs This vendible applies to the lawmaking in git master only ##Introduction The bitcoinj networking APIs have a few options targeted at variegated use-cases - you can spin up individual Peers and manage them yourself or bring up a PeerGroup to let it manage them, you can use one-off sockets or socket managers, and you can use blocking sockets or NIO/non-blocking sockets. This page attempts to explain the tradeoffs and use-cases for each choice, as well as provide some vital examples to doing increasingly wide networking. The bitcoinj networking API is built up in a series of layers. On the marrow are simple wrapper classes that provide an API to unshut new connections using blocking sockets or java NIO (asynchronous select()-based sockets). On top of those sit various parsers that parse the network traffic into messages (ie into the Bitcoin messages). On top of those are Peer objects, which handle message handling (exchanging initial version handshake, downloading blocks, etc) for each individual remote peer and provide a simple event listener interface. Finally a PeerGroup can be layered on top to alimony track of peers, ensuring there are unchangingly unbearable connections to the network and keeping track of network sync progress. ##The simple specimen In the specimen that you simply want a connection to the P2P network (ie in the vast majority of cases), all you need to do is instantiate a PeerGroup and connect a few objects: PeerGroup peerGroup = new PeerGroup(networkParameters, blockChain); peerGroup.setUserAgent("Sample App", 1.0); peerGroup.addWallet(wallet); peerGroup.addPeerDiscovery(new DnsDiscovery(networkParameters)); peerGroup.startAndWait(); peerGroup.downloadBlockChain(); After this lawmaking completes you’ve unfluctuating to some peers and fully downloaded the blockchain up to the latest block, filling in missing wallet transactions as it goes. peerGroup.startAndWait() and peerGroup.downloadBlockChain() can be replaced with asynchronous versions peerGroup.start() followed by peerGroup.startBlockchainDownload(listener) when the future returned by start() completes. ##Proxying If you wish to connect to the network using a SOCKS proxy, you must use blocking sockets instead of nio ones. This makes network slightly less efficient, but it should not be noticeable for anything short of very heavy workloads. Then you simply set the Java system properties for a SOCKS proxy (as below) and connections will automatically spritz over the proxy. System.setProperty("socksProxyHost", "127.0.0.1"); System.setProperty("socksProxyPort", "9050"); peerGroup = new PeerGroup(params, chain, new BlockingClientManager()); ##Experimental: Using Tor When using Tor, most apps will connect to the network via a local SOCKS proxy. Whilst you could do that as well it has a number of disadvantages, most obviously that you need a local Tor vendee running already. With bitcoinj we have a largest choice, which is using the Orchid library - a pure Java implementation of the Tor protocol. Orchid is included in bitcoinj automatically, so you do not have to do anything to goody from it. However due to performance and reliability concerns Tor is not yet enabled by default, so to use it you must do something like this: // If using WalletAppKit: kit.useTor(); // If constructing a PeerGroup by hand: PeerGroup peerGroup = PeerGroup.newWithTor(params, chain, new TorClient()); The TorClient object can be used to construct new sockets that are routed via Tor, for example, if you wish to use Tor for your own HTTPS requests this is the right way to do that. There are some important things to note here. The first is that in 0.12, the Tor support finds peers by towers many diverse circuits and querying DNS through all of them. This is very slow but reduces the impact a bad Tor exit can have on peer discovery. In 0.13 things reverted such that peers are discovered by a simple, fast HTTP request to a Cartographer seed. The HTTP response is digitally signed so bad exits cannot tamper with it. This boosts startup performance considerably, at a forfeit of (temporarily) reduced seed diversity. In future, we hope that increasingly people will run Cartographer seeds and we will combine the strengths of both approaches. Tor support is likely to get increasingly well-constructed and integrated in future versions of the library. ##Using the lower level API’s You can build a Peer at a lower level, executive the socket to be used, using lawmaking like this: Peer peer = new Peer(params, bitcoin.chain(), new PeerAddress(InetAddress.getLocalHost(), 8333), "test app", "0.1") { @Override public void connectionOpened() { super.connectionOpened(); System.out.println("TCP connect done"); } }; peer.addEventListener(new AbstractPeerEventListener() { @Override public void onPeerConnected(Peer peer, int peerCount) { System.out.println("Version handshake done"); } }); new BlockingClient(address, peer, 10000, SocketFactory.getDefault(), null); Of undertow you would provide your own SocketFactory instead of using the default. If you want wangle to a raw stream of messages with no higher level logic, subclass PeerSocketHandler and override the processMessage utopian method. This matriculation implements StreamParser which breaks raw byte streams into the right subclass of Message for you, and then lets you handle those messages as you see fit. Create instances of your new object and pass them to an implementation of ClientConnectionManager, typically either BlockingClientManager or NioClientManager to use epoll/select based async IO.