pickynode 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pickynode +47 -24
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc0ef2704c9184ce652cd12af4ee96ee988bc736
4
- data.tar.gz: 9c19242a064f84086ab8e73e8b236bce762fedf1
3
+ metadata.gz: a9ed335fbc05dfe5122819dab044c3f087f6855d
4
+ data.tar.gz: ae580a59583a6c5b355883ee71e76cf8b30f8665
5
5
  SHA512:
6
- metadata.gz: f77e1a6596316b140a708fefa357d74a9636c37f81734b407e559e4df725080514de35cf753a8a09fadb864a521e95b0f8cdc6973346d40ccf9869cd6b84337e
7
- data.tar.gz: 76d8f030acbb90b34de574d255e9f7eb2b1304ce181d518fc34d62afa101c34504ec7f1e7c46faa3e1ba9e6100a92bdf151850eb4c191c21babcc2666d0c1773
6
+ metadata.gz: 1051e7d02b39ee86c2a2cc031d484c5f00ac9ee21c9634822395a10ff03702560ff9d5c76d24a4e8fad5374594920b8b42969dfca2159b5161a28c22a86be952
7
+ data.tar.gz: 7d215790b39f5b36b0f05cb0e4f4e47bdaaa552e4b975d81a6452e558740f0bdf84cf3818879be03fdc44b2366a3e0e8709df101f1a7faf48161e122f1281ec8
data/bin/pickynode CHANGED
@@ -6,15 +6,16 @@ require 'pp'
6
6
  require 'trollop'
7
7
  require 'uri'
8
8
 
9
- VERSION = "0.0.2"
9
+ VERSION = "0.0.3"
10
10
 
11
11
  opts = Trollop::options do
12
12
  version "pickynode v#{VERSION}"
13
- opt :add, "Node type to add", :type => :string
14
- opt :ban, "Node type to ban", :type => :string
13
+ opt :add, "Add node type", :type => :string
14
+ opt :connect, "Connect to node type", :type => :string
15
+ opt :ban, "Ban node type", :type => :string
15
16
  opt :debug, "Debug mode"
16
17
  opt :output, "Output commands"
17
- opt :disconnect, "Node type to disconnect", :type => :string
18
+ opt :disconnect, "Disconnect from node type", :type => :string
18
19
  end
19
20
 
20
21
  def run(cmd, opts={})
@@ -22,36 +23,58 @@ def run(cmd, opts={})
22
23
  `#{cmd}` unless opts[:debug]
23
24
  end
24
25
 
25
- if filter = opts[:add]
26
+ def get_addr_types
27
+ nodes = `bitcoin-cli getpeerinfo`
28
+ parsed_nodes = JSON.parse(nodes)
29
+ parsed_nodes.map { |n| [n["addr"], n["subver"]] }.to_h
30
+ end
31
+
32
+ def get_bitnode_addr_types
26
33
  u = URI.parse("https://bitnodes.21.co/api/v1/snapshots/latest/")
27
34
  nodelist = Net::HTTP.get(u)
28
35
  parsed_nodelist = JSON.parse(nodelist)
29
- bitnode_addr_types = parsed_nodelist['nodes'].map { |k,v| [k, v[1]] }.to_h
30
- bitnode_addr_types.each do |k,v|
31
- if v.include?(filter)
32
- u = URI.parse("https://#{k}")
33
- run(%^bitcoin-cli addnode "#{u.host}" "add"^, opts)
36
+ parsed_nodelist['nodes'].map { |k,v| [k, v[1]] }.to_h
37
+ end
38
+
39
+ if opts[:add] || opts[:connect]
40
+ bitnode_addr_types = get_bitnode_addr_types
41
+
42
+ if filter = opts[:add]
43
+ bitnode_addr_types.each do |k,v|
44
+ if v.include?(filter)
45
+ u = URI.parse("https://#{k}")
46
+ run(%^bitcoin-cli addnode "#{u.host}" "add"^, opts)
47
+ end
48
+ end
49
+ end
50
+
51
+ if filter = opts[:connect]
52
+ bitnode_addr_types.each do |k,v|
53
+ if v.include?(filter)
54
+ u = URI.parse("https://#{k}")
55
+ run(%^bitcoin-cli addnode "#{u.host}" "onetry"^, opts)
56
+ end
34
57
  end
35
58
  end
36
59
  end
37
60
 
38
- nodes = `bitcoin-cli getpeerinfo`
39
- parsed_nodes = JSON.parse(nodes)
40
- addr_types = parsed_nodes.map { |n| [n["addr"], n["subver"]] }.to_h
61
+ if opts[:ban] || opts[:disconnect]
62
+ addr_types = get_addr_types
41
63
 
42
- if filter = opts[:disconnect]
43
- addr_types.each do |k,v|
44
- if v.include?(filter)
45
- run(%^bitcoin-cli disconnectnode "#{k}"^, opts)
64
+ if filter = opts[:ban]
65
+ addr_types.each do |k,v|
66
+ if v.include?(filter)
67
+ u = URI.parse("https://#{k}")
68
+ run(%^bitcoin-cli setban "#{u.host}" "add"^, opts)
69
+ end
46
70
  end
47
71
  end
48
- end
49
72
 
50
- if filter = opts[:ban]
51
- addr_types.each do |k,v|
52
- if v.include?(filter)
53
- u = URI.parse("https://#{k}")
54
- run(%^bitcoin-cli setban "#{u.host}" "add"^, opts)
73
+ if filter = opts[:disconnect]
74
+ addr_types.each do |k,v|
75
+ if v.include?(filter)
76
+ run(%^bitcoin-cli disconnectnode "#{k}"^, opts)
77
+ end
55
78
  end
56
79
  end
57
80
  end
@@ -60,4 +83,4 @@ unless opts.values.select { |v| v }.empty?
60
83
  exit(0)
61
84
  end
62
85
 
63
- ap addr_types
86
+ ap get_addr_types
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickynode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Ellithorpe