{"id":13775757,"url":"https://github.com/mojombo/proxymachine","last_synced_at":"2025-04-08T00:38:22.228Z","repository":{"id":554460,"uuid":"185041","full_name":"mojombo/proxymachine","owner":"mojombo","description":"A simple TCP routing proxy built on EventMachine that lets you configure the routing logic in Ruby.","archived":false,"fork":false,"pushed_at":"2022-05-24T18:17:52.000Z","size":212,"stargazers_count":584,"open_issues_count":6,"forks_count":86,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-02T22:36:52.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mojombo.png","metadata":{"files":{"readme":"README.md","changelog":"History.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-04-25T01:40:04.000Z","updated_at":"2025-03-25T07:52:48.000Z","dependencies_parsed_at":"2022-07-04T23:01:48.654Z","dependency_job_id":null,"html_url":"https://github.com/mojombo/proxymachine","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mojombo%2Fproxymachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mojombo%2Fproxymachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mojombo%2Fproxymachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mojombo%2Fproxymachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mojombo","download_url":"https://codeload.github.com/mojombo/proxymachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755560,"owners_count":20990620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:48.440Z","updated_at":"2025-04-08T00:38:22.203Z","avatar_url":"https://github.com/mojombo.png","language":"Ruby","funding_links":[],"categories":["\u003ca id=\"d03d494700077f6a65092985c06bf8e8\"\u003e\u003c/a\u003e工具","Ruby"],"sub_categories":["\u003ca id=\"0ff94312f3ab4898f5996725133ea9d1\"\u003e\u003c/a\u003e未分类"],"readme":"ProxyMachine\n============\n\nBy Tom Preston-Werner (tom@mojombo.com)\n\n\nDescription\n-----------\n\nProxyMachine is a simple content aware (layer 7) TCP routing proxy built on\nEventMachine that lets you configure the routing logic in Ruby.\n\nIf you need to proxy connections to different backend servers depending on the\ncontents of the transmission, then ProxyMachine will make your life easy!\n\nThe idea here is simple. For each client connection, start receiving data\nchunks and placing them into a buffer. Each time a new chunk arrives, send the\nbuffer to a user specified block. The block's job is to parse the buffer to\ndetermine where the connection should be proxied. If the buffer contains\nenough data to make a determination, the block returns the address and port of\nthe correct backend server. If not, it can choose to do nothing and wait for\nmore data to arrive, close the connection, or close the connection after\nsending custom data. Once the block returns an address, a connection to the\nbackend is made, the buffer is replayed to the backend, and the client and\nbackend connections are hooked up to form a transparent proxy. This\nbidirectional proxy continues to exist until either the client or backend\nclose the connection.\n\nProxyMachine was developed for GitHub's federated architecture and is\nsuccessfully used in production to proxy millions of requests every day. The\nperformance and memory profile have both proven to be excellent.\n\n\nInstallation\n------------\n\n    $ gem install proxymachine -s http://gemcutter.org\n\n\nRunning\n-------\n\n    Usage:\n      proxymachine -c \u003cconfig file\u003e [-h \u003chost\u003e] [-p \u003cport\u003e]\n\n    Options:\n      -c, --config CONFIG              Configuration file\n      -h, --host HOST                  Hostname to bind. Default 0.0.0.0\n      -p, --port PORT                  Port to listen on. Default 5432\n\n\nSignals\n-------\n\n    QUIT - Graceful shutdown. Stop accepting connections immediately and\n           wait as long as necessary for all connections to close.\n\n    TERM - Fast shutdown. Stop accepting connections immediately and wait\n           up to 10 seconds for connections to close before forcing\n           termination.\n\n    INT  - Same as TERM\n\n\nExample routing config file\n---------------------------\n\n    class GitRouter\n      # Look at the routing table and return the correct address for +name+\n      # Returns \"\u003chost\u003e:\u003cport\u003e\" e.g. \"ae8f31c.example.com:9418\"\n      def self.lookup(name)\n        ...\n      end\n    end\n\n    # Perform content-aware routing based on the stream data. Here, the\n    # header information from the Git protocol is parsed to find the \n    # username and a lookup routine is run on the name to find the correct\n    # backend server. If no match can be made yet, do nothing with the\n    # connection.\n    proxy do |data|\n      if data =~ %r{^....git-upload-pack /([\\w\\.\\-]+)/[\\w\\.\\-]+\\000host=\\w+\\000}\n        name = $1\n        { :remote =\u003e GitRouter.lookup(name) }\n      else\n        { :noop =\u003e true }\n      end\n    end\n\n\nExample SOCKS4 Proxy in 7 Lines\n-------------------------------\n\n    proxy do |data|\n      return  if data.size \u003c 9\n      v, c, port, o1, o2, o3, o4, user = data.unpack(\"CCnC4a*\")\n      return { :close =\u003e \"\\0\\x5b\\0\\0\\0\\0\\0\\0\" }  if v != 4 or c != 1\n      return  if ! idx = user.index(\"\\0\")\n      { :remote =\u003e \"#{[o1,o2,o3,o4]*'.'}:#{port}\",\n        :reply =\u003e \"\\0\\x5a\\0\\0\\0\\0\\0\\0\",\n        :data =\u003e data[idx+9..-1] }\n    end\n\n\nValid return values\n-------------------\n\n`{ :remote =\u003e String }` - String is the host:port of the backend server that will be proxied.  \n`{ :remote =\u003e String, :data =\u003e String }` - Same as above, but send the given data instead.  \n`{ :remote =\u003e String, :data =\u003e String, :reply =\u003e String}` - Same as above, but reply with given data back to the client\n`{ :noop =\u003e true }` - Do nothing.  \n`{ :close =\u003e true }` - Close the connection.  \n`{ :close =\u003e String }` - Close the connection after sending the String.  \n\nConnection Errors and Timeouts\n------------------------------\n\nIt's possible to register a custom callback for handling connection\nerrors. The callback is passed the remote when a connection is either\nrejected or a connection timeout occurs:\n\n    proxy do |data|\n      if data =~ /your thing/\n        { :remote =\u003e 'localhost:1234', :connect_timeout =\u003e 1.0 }\n      else\n        { :noop =\u003e true }\n      end\n    end\n\n    proxy_connect_error do |remote|\n      puts \"error connecting to #{remote}\"\n    end\n\nYou must provide a `:connect_timeout` value in the `proxy` return value\nto enable connection timeouts. The `:connect_timeout` value is a float\nrepresenting the number of seconds to wait before a connection is\nestablished. Hard connection rejections always trigger the callback, even\nwhen no `:connect_timeout` is provided.\n\nInactivity Timeouts\n-------------------\n\nInactivity timeouts work like connect timeouts but are triggered after\nthe configured amount of time elapses without receiving the first byte\nof data from an already connected server:\n\n    proxy do |data|\n      { :remote =\u003e 'localhost:1234', :inactivity_timeout =\u003e 10.0 }\n    end\n\n    proxy_inactivity_error do |remote|\n      puts \"#{remote} did not send any data for 10 seconds\"\n    end\n\nIf no `:inactivity_timeout` is provided, the `proxy_inactivity_error`\ncallback is never triggered.\n\nContribute\n----------\n\nIf you'd like to hack on ProxyMachine, start by forking my repo on GitHub:\n\nhttp://github.com/mojombo/proxymachine\n\nTo get all of the dependencies, install the gem first. The best way to get\nyour changes merged back into core is as follows:\n\n1. Clone down your fork\n1. Create a topic branch to contain your change\n1. Hack away\n1. Add tests and make sure everything still passes by running `rake`\n1. If you are adding new functionality, document it in the README.md\n1. Do not change the version number, I will do that on my end\n1. If necessary, rebase your commits into logical chunks, without errors\n1. Push the branch up to GitHub\n1. Send me (mojombo) a pull request for your branch\n\n\nCopyright\n---------\n\nCopyright (c) 2009 Tom Preston-Werner. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmojombo%2Fproxymachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmojombo%2Fproxymachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmojombo%2Fproxymachine/lists"}