Giter VIP home page Giter VIP logo

p5-io-socket-socks-wrapper's Introduction

IO::Socket::Socks::Wrapper
===========================================

IO::Socket::Socks::Wrapper allows to wrap up the network connections into socks proxy.

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES

This module requires these other modules and libraries:

  IO::Socket::Socks

COPYRIGHT AND LICENCE

Oleg G

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

p5-io-socket-socks-wrapper's People

Contributors

olegwtf avatar chorny avatar

Stargazers

VD $ VD171 @ Priv8 avatar Stanislaw Pusep avatar

Watchers

 avatar VD $ VD171 @ Priv8 avatar

Forkers

chorny

p5-io-socket-socks-wrapper's Issues

telnet timeouts not returning correctly

First, my apologies if this is addressed in a newer version - we have
IO::Socket:Socks v. 0.67
IO::Socket::Socks::Wrapper v. 0.14

The wrapper is applied globally before any other connection related libs are included:

require IO::Socket::Socks::Wrapper;
IO::Socket::Socks::Wrapper->import({ProxyAddr => $Socks5Host,
	ProxyPort => $Socks5Port,
	Timeout => 30,
	SocksDebug => 0});

The file where this happens calls a second file that loops over connecting to a number of devices with the following code:
use Net::Telnet;

	my $telnet = new Net::Telnet(
		Timeout => 2,
		Cmd_remove_mode => 1,
		Errmode => 'return',
		Dump_Log => $DebugLog,
		Prompt => '/-->\s*$/i'
	);
	my $error;
	# Ok, open the connection
	if(!$telnet->open($self->{'ip'})) {
		$error="Could not connect to ONT ($self->{'ip'}) - " . $telnet->errmsg();
		return (0,$error);
	}

If any of these devices happen to not be online, and open() times out, it does not return $error, but instead exits back to the first file.

Ability to integrate into event-loop

We need ability to use IO::Socket::Socks::Wrapper with non-blocking event loops like POE, anyevent, Mojo::IOLoop and so on
The idea is:
tie $socket inside _connect()
In Tie class FILENO() should return fileno to fake file descriptor which will return non-ready status for write (and maybe read) when asking whith select/poll/etc while socks handshake not done. Here some ideas how to create such file descriptor: http://www.linux.org.ru/forum/development/10772549?lastmod=1408291493471. At the same time we should start making non-blocking socks handshake inside _connect(), adding appropriate polling for event loop. User of the module should set how to do proper poll inside this event loop with config like this (examples for Mojo::IOLoop and AnyEvent):

{
    init_io_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;

        Mojo::IOLoop->singleton->reactor->io($hdl => sub {
            my $writable = pop;

            if ($writable) {
                $writable_cb->();
            }
            else {
                $readable_cb->();
            }
        })
    },
    set_read_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;
        Mojo::IOLoop->singleton->reactor->watch($hdl, 1, 0);
    },
    unset_read_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;
        Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 0);
    },
    set_write_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;
        Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 1);
    },
    unset_write_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;
        Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 0);
    },
    destroy_io_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;
        Mojo::IOLoop->singleton->reactor->remove($hdl);
    }
}
{
    my $w;

    init_io_watcher => undef,
    set_read_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;

        $w = AnyEvent->io(
            fh   => $hdl,
            poll => 'r',
            cb   => sub {
                $readable_cb->();
            }
        )
    },
    unset_read_watcher => sub {
        undef $w;
    },
    set_write_watcher => sub {
        my ($hdl, $readable_cb, $writable_cb) = @_;

        $w = AnyEvent->io(
            $fh  => $hdl,
            poll => 'w',
            cb   => sub {
                $writable_cb->();
            }
        );
    },
    unset_write_watcher => sub {
        undef $w;
    },
    destroy_io_watcher => undef
}

After socks handshake done we will make dup2(io_socket_socks_fd, fake_fd). So, now fake_fd is real fd of the socket and will indicate as ready for write().

How to avoid local Name Resolution?

Hello and my appologies for stealing your time with this probably stupid question, I am not into Network Programming at all.^^

The Problem I am trying to solve is about connecting to a LDAP Server through a Socks Proxy, with no local name Resolution possible.

here is the relevant code:
IO::Socket::Socks::Wrapper->import( 'Net::LDAP::connect_ldap()' => { ProxyAddr => $proxy, ProxyPort => $proxy_port, Timeout => 5, SocksDebug => 0 } ); my $ldap = Net::LDAP->new($ldap_uri); if (!$ldap) { _debug(2, "could not establish connection: $@"); return 0; }
I thought that the name Resolution is automatically done by the Proxy Server, but i get this Error from my debug output
...could not establish connection: IO::Socket::INET: Bad hostname 'somehost.com'

Setting local names in /etc/hosts does solve that issue but its not the way it should work.
Am I using your module wrong or do i have to lookup the names before hand through the proxy and pass the ip to ldap connection?

Thank you very much in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.