ipfs_public_gateway_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 924f869e9bb4c80049a1d71184b9b36bdadf66ccb6d6420e4a8dce6ba612afdc
4
+ data.tar.gz: b3a3fe1272bf74d2c014c6c00d01dffaffa92d29b60bfb8dbb352226cb4d52f7
5
+ SHA512:
6
+ metadata.gz: 26b8ad1534688c69e64efc3a1c4dfd230c5678e4ec314456c8255a7a34b67c25fa1c6bb777d4ad906de30d3e6a260f57057b527aa6dcd3f1653aae72e236f34e
7
+ data.tar.gz: 6a018ef87a4fc43a83fad795377b433c3e7ebe0d0dda2d526ac7026bb79d4d6500d60cd2472fc4444be381cfbf3726367025b21ae9363e6e8f0645870901d9b3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at idegorepl@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # IPFS Public Gateway Checker
2
+
3
+ This's a Golang version which migrates from:
4
+
5
+ * [public-gateway-checker](https://github.com/ipfs/public-gateway-checker) An online webpage of JS version
6
+ * [ipfg](https://github.com/JayBrown/Tools/tree/master/ipfg) A shell cli version
7
+ * [ipfg](https://github.com/gingerhot/ipfg) A Golang version
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'ipfs_public_gateway_checker'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install ipfs_public_gateway_checker
24
+
25
+ ## Usage
26
+
27
+ After installation, there will be a command `ipfg` available for you.
28
+
29
+ ```bash
30
+ ipfg # to get one available gateway url for you
31
+ ipfg all # get all available gateway urls
32
+ ipfg help # show help message
33
+ ```
34
+ And you can require the gem in your code, just as what I do in the [bin/ipfg](./bin/ipfg).
35
+ There're two methods for you: `get()` and `active_list()`.
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/beijingrb/ipfs_public_gateway_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the IpfsPublicGatewayChecker project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beijingrb/ipfs_public_gateway_checker/blob/master/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ipfs_public_gateway_checker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/ipfg ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ipfs_public_gateway_checker'
4
+
5
+ def help
6
+ puts <<USAGE
7
+ ipfg - A command line to get available IPFS public gateway list
8
+
9
+ Usage: "ipfg" to get maybe the fastest one of gateways
10
+ "ipfg all" to get all available gateways
11
+ USAGE
12
+ end
13
+
14
+ if ARGV.length == 0
15
+ puts IpfsPublicGatewayChecker.get
16
+ elsif ARGV.length == 1 && ARGV[0] == 'all'
17
+ puts IpfsPublicGatewayChecker.active_list
18
+ else
19
+ help
20
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ipfs_public_gateway_checker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ipfs_public_gateway_checker"
8
+ spec.version = IpfsPublicGatewayChecker::VERSION
9
+ spec.authors = ["B1nj0y"]
10
+ spec.email = ["idegorepl@gmail.com"]
11
+
12
+ spec.summary = %q{IPFS Public Gateway Checker}
13
+ spec.description = %q{Checks which public gateways are online or not.}
14
+ spec.homepage = "https://github.com/beijingrb/ipfs_public_gateway_checker"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = %w[ipfs_public_gateway_checker.gemspec] + Dir["*.md", "bin/*", "lib/**/*.rb"]
18
+ spec.executables = %w[ipfg]
19
+ spec.require_paths = %w[lib]
20
+
21
+ spec.add_dependency "rest-client", "~> 2.0"
22
+ spec.add_dependency "parallel", "~> 1.12"
23
+ spec.add_dependency "concurrent-ruby-edge", "~> 0.4"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,59 @@
1
+ require "ipfs_public_gateway_checker/version"
2
+ require "rest-client"
3
+ require "parallel"
4
+ require 'concurrent-edge'
5
+ require "json"
6
+
7
+ module IpfsPublicGatewayChecker
8
+ HASH_TO_TEST = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a'
9
+ HASH_STRING = 'Hello from IPFS Gateway Checker'
10
+ GATEWAY_LIST_URL = 'https://raw.githubusercontent.com/ipfs/public-gateway-checker/master/gateways.json'
11
+
12
+ Channel = Concurrent::Channel
13
+
14
+ class << self
15
+ # get the possible fastest one
16
+ def get
17
+ list = gateway_list
18
+ return unless list
19
+ ch = Channel.new
20
+ list.each do |url|
21
+ Channel.go do
22
+ test_url = url.sub(':hash', HASH_TO_TEST)
23
+ ch << url if check(test_url)
24
+ end
25
+ end
26
+ ~ch
27
+ end
28
+
29
+ # get all active gateway list
30
+ # I've tried to use concurrent-edge to do this parallel detecting but
31
+ # there's always some problem. Perhaps I havn't grasped the gem's usage yet,
32
+ # or due to it's still experimental. Then I use the more robust Parallel gem
33
+ def active_list
34
+ list = gateway_list
35
+ return unless list
36
+ active_gateways = []
37
+ Parallel.map(list, in_threads: list.length) do |url|
38
+ test_url = url.sub(':hash', HASH_TO_TEST)
39
+ active_gateways << url if check(test_url)
40
+ end
41
+ active_gateways&.compact
42
+ end
43
+
44
+ def gateway_list
45
+ JSON.parse(RestClient.get(GATEWAY_LIST_URL) || '')
46
+ end
47
+
48
+ def check(url, timeout=5)
49
+ begin
50
+ resp = RestClient::Request.execute(method: :get, url: url, timeout: timeout)
51
+ rescue
52
+ return false
53
+ end
54
+ # puts resp.body
55
+ return false unless resp.code == 200
56
+ resp.body&.chomp == HASH_STRING
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module IpfsPublicGatewayChecker
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipfs_public_gateway_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - B1nj0y
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parallel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: concurrent-ruby-edge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Checks which public gateways are online or not.
84
+ email:
85
+ - idegorepl@gmail.com
86
+ executables:
87
+ - ipfg
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - CODE_OF_CONDUCT.md
92
+ - README.md
93
+ - bin/console
94
+ - bin/ipfg
95
+ - bin/setup
96
+ - ipfs_public_gateway_checker.gemspec
97
+ - lib/ipfs_public_gateway_checker.rb
98
+ - lib/ipfs_public_gateway_checker/version.rb
99
+ homepage: https://github.com/beijingrb/ipfs_public_gateway_checker
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.7.8
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: IPFS Public Gateway Checker
123
+ test_files: []