locoyo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7ac2d02d2de7e08eb658b0088eddedff27dad46
4
+ data.tar.gz: 848a3b870d5d8991e011a0691906225b585dc743
5
+ SHA512:
6
+ metadata.gz: 2fdeff02a2a0d0ff1c0363d520454e4913c2d8f15e8291b0778a7c737596d3d8f88e07fa8d571c8190664d15db9edaa2f00e8b4ec41ea71e5879a218a40872e7
7
+ data.tar.gz: 053d60415e0c9c760e3e5a48df6efba69cb66bcd97c391a373a239649009bc60209740e3e756979164ecb3885026e3d71779f370a44180e6f4d2e6999a30caff
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in locoyo.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris Teague
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Locoyo
2
+
3
+ Very ALPHA!! Use completely at your own risk.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'locoyo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install locoyo
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/chris-teague/locoyo/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,139 @@
1
+ require "locoyo/version"
2
+ require 'eventmachine'
3
+ require 'json'
4
+ require 'pry'
5
+ require 'em-http-request'
6
+ require 'zlib'
7
+ require 'fiber'
8
+
9
+ module Locoyo
10
+ class ClientHandler < EM::Connection
11
+
12
+ attr_accessor :port, :subdomain, :key, :address, :protocol, :connected
13
+
14
+ def initialize(options = {})
15
+ options = {
16
+ port: 3000,
17
+ address: '127.0.0.1',
18
+ protocol: 'http'
19
+ }.merge(options)
20
+ self.port = options[:port]
21
+ self.address = options[:address]
22
+ self.protocol = options[:protocol]
23
+ self.connected = false
24
+ super
25
+ end
26
+
27
+ # Test that this is setup and working...
28
+ def connection_completed
29
+ start_tls
30
+ end
31
+
32
+ def receive_data(data)
33
+ json = JSON.parse(data)
34
+ send(json['type'], json['data'])
35
+ rescue => e
36
+ puts e
37
+ end
38
+
39
+ def ssl_handshake_completed
40
+ send_data('connect')
41
+ end
42
+
43
+ def unbind
44
+ @connected = false
45
+ end
46
+
47
+ protected
48
+
49
+ def new_connection(data)
50
+ self.subdomain = data['subdomain']
51
+ self.key = data['key']
52
+ @connected = true
53
+ end
54
+
55
+ def delegate_request(options)
56
+ http = EventMachine::HttpRequest.new("#{protocol}://#{address}:#{port}").send(options['method'].downcase, path: options['path'], head: options['headers'], body: options['body'], query: options['query'])
57
+ http.callback {
58
+
59
+ encoding = http.response.encoding.name
60
+ if encoding == 'UTF-8'
61
+ encoded_data = Base64.encode64(Zlib::Deflate.deflate(http.response))
62
+ else
63
+ encoded_data = Base64.encode64(http.response)
64
+ end
65
+
66
+ response = {
67
+ status: http.response_header.status,
68
+ content_type: http.response_header["CONTENT_TYPE"],
69
+ body: encoded_data,
70
+ encoding: encoding,
71
+ uuid: options['uuid']
72
+ }
73
+ send_data(response.to_json)
74
+ }
75
+ end
76
+
77
+ end
78
+
79
+ class Tunnel
80
+
81
+ attr_accessor :connection, :port, :address, :protocol, :remote_address, :remote_port
82
+
83
+ def initialize(options = {})
84
+ options = {
85
+ port: 3000,
86
+ address: '127.0.0.1',
87
+ protocol: 'http',
88
+ remote_address: 'client.uxspec.com',
89
+ remote_port: 5000
90
+ }.merge(options)
91
+
92
+ self.port = options[:port]
93
+ self.address = options[:address]
94
+ self.protocol = options[:protocol]
95
+ self.remote_address = options[:remote_address]
96
+ self.remote_port = options[:remote_port]
97
+ self.connection = nil
98
+
99
+ Thread.new { EventMachine.run }
100
+ while not EM.reactor_running?; end
101
+ end
102
+
103
+ def run
104
+ @connection = EventMachine.connect(
105
+ @remote_address,
106
+ @remote_port,
107
+ ClientHandler, { port: @port, address: @address, protocol: @protocol }
108
+ )
109
+ end
110
+
111
+ def get_subdomain
112
+
113
+ # Fiber.new {
114
+ # fiber = Fiber.current
115
+
116
+ # EM.add_timer(5) { fiber.resume(nil) }
117
+ # EM.add_periodic_timer(0.01) do
118
+ # if @connection && @connection.connected
119
+ # puts 'OSOGHSOGNOS'
120
+ # puts @connection.subdomain
121
+ # fiber.resume(@connection.subdomain)
122
+ # end
123
+ # end
124
+ # Fiber.yield(fiber.transfer)
125
+ # # result = Fiber.yield('cocks')
126
+ # # puts "result: #{result}"
127
+ # # return result
128
+ # }.resume
129
+
130
+ @connection.subdomain
131
+ end
132
+
133
+ def stop
134
+ EventMachine.stop
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,3 @@
1
+ module Locoyo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locoyo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "locoyo"
8
+ spec.version = Locoyo::VERSION
9
+ spec.authors = ["Chris Teague"]
10
+ spec.email = ["chris@cteague.com.au"]
11
+ spec.summary = %q{Locoyo client app}
12
+ spec.description = %q{Locoyo client app}
13
+ spec.homepage = "https://github.com/chris-teague/locoyo"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'eventmachine', '~> 1.0', '>= 1.0.7'
22
+ spec.add_runtime_dependency 'em-http-request', '~> 1.1', '>= 1.1.2'
23
+
24
+ spec.add_development_dependency "pry", "~> 0.10.0"
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locoyo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Teague
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eventmachine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: em-http-request
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: pry
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 0.10.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 0.10.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.7'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.7'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '10.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '10.0'
95
+ description: Locoyo client app
96
+ email:
97
+ - chris@cteague.com.au
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - lib/locoyo.rb
108
+ - lib/locoyo/version.rb
109
+ - locoyo.gemspec
110
+ homepage: https://github.com/chris-teague/locoyo
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.5.1
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Locoyo client app
134
+ test_files: []