NAME
Net::Proxy - Framework for proxying network connections in many ways
SYNOPSIS
use Net::Proxy;
# proxy connections from localhost:6789 to remotehost:9876
# using standard TCP connections
my $proxy = Net::Proxy->new(
in => { proto => tcp, port => '6789' },
out => { proto => tcp, host => 'remotehost', port => '9876' },
);
# register the proxy object
$proxy->register();
# and you can setup multiple proxies
# and now proxy connections indefinitely
Net::Proxy->mainloop();
DESCRIPTION
A Net::Proxy object represents a proxy that accepts connections and then relays the data transfered between the source and the destination.
The goal of this module is to abstract the different protocols used to connect from the proxy to the destination. See "AVAILABLE CONNECTORS"
METHODS
If you only intend to use Net::Proxy and not write new connectors, you only need to know about new(), register() and mainloop().
Class methods
- new( { in => { ... }, { out => { ... } } )
-
Return a new
Net::Proxyobject, with two connectors configured as described in the hashref. - mainloop( $max_connections )
-
This method initialises all the registered
Net::Proxyobjects and then loops on all the sockets ready for reading, passing the data through the variousNet::Proxy::Connectorobjets to handle the specifics of each connection.If
$max_connectionsis given, the proxy will stop after having fully processed that many connections. Otherwise, this method does not return. - add_listeners( @sockets )
-
Add the given sockets to the list of listening sockets.
- watch_sockets( @sockets )
-
Add the given sockets to the watch list.
- close_sockets( @sockets )
-
Close the given sockets and cleanup the related internal structures.
Some of the class methods are related to the socket objects handling the actual connections.
- get_peer( $socket )
- set_peer( $socket, $peer )
-
Get or set the socket peer.
- get_connector( $socket )
- set_connector( $socket, $connector )
-
Get or set the socket connector (a
Net::Proxy::Connectorobject). - get_state( $socket )
- set_state( $socket, $state )
-
Get or set the socket state. Some
Net::Proxy::Connectorclasses may wish to use this to store some internal information about the socket or the connection.
Instance methods
- register()
-
Register a
Net::Proxyobject so that it will be included in themainloop()processing. - unregister()
-
Unregister the
Net::Proxyobject. - in_connector()
-
Return the
Net::Proxy::Connectorobjet that handles the incoming connection and handles the data coming from the "client" side. - out_connector()
-
Return the
Net::Proxy::Connectorobjet that creates the outgoing connection and handles the data coming from the "server" side.
AVAILABLE CONNECTORS
All connection types are provided with the help of specialised classes. The logic for protocol xxx is provided by the Net::Proxy::Connector::xxx class.
tcp (Net::Proxy::Connector::tcp)
This is the simplest possible proxy. On the "in" side, it sits waiting for incoming connections, and on the "out" side, it connects to the configured host/port.
dummy (Net::Proxy::Connector::dummy)
This proxy does nothing. You can use it as a template for writing new Net::Proxy::Connector classes.
Summary
This table summarises all the available Net::Proxy::Connector classes and the parameters their constructors recognise.
Connector | in parameters | out parameters
------------+-----------------+----------------
tcp | host | host
| port | port
------------+-----------------+----------------
dummy | N/A | N/A
AUTHOR
Philippe 'BooK' Bruhat, <book@cpan.org>.
BUGS
Please report any bugs or feature requests to bug-net-proxy@rt.cpan.org, or through the web interface at http://rt.cpan.org/. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
TODO
Here's my own wishlist:
port
connect-tunnelto useNet::Proxy.This requires writing
Net::Proxy::Connector::connect.port
sslh(unreleased reverse proxy that can listen on a port and proxy to a SSH server or a HTTPS server depending on the client) to useNet::Proxy.This requires writing
Net::Proxy::Connector::dual.write a script fully compatible with GNU httptunnel (http://www.nocrew.org/software/httptunnel.html.
This requires writing
Net::Proxy::Connector::httptunnel.enhance the httptunnel protocol to support multiple connections
This requires writing
Net::Proxy::Connector::httptunnel2(or whatever I may call it then).Add support for filters, so that the data can be transformed on the fly (could be useful to deceive intrusion detection systems, for example).
COPYRIGHT & LICENSE
Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.