Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frequent breakdowns #43

Open
davejakenic opened this issue Aug 10, 2022 · 0 comments
Open

frequent breakdowns #43

davejakenic opened this issue Aug 10, 2022 · 0 comments

Comments

@davejakenic
Copy link

davejakenic commented Aug 10, 2022

I implemented a class torsocket to replace socket for P2P communication.
It works in principle, but of 1000 attempts for connection I might have one successful send/recv and 999 TimeOutErrors.

class Torsocket:
    def __init__(self,ip,port):
        self.mgr1    = TorClient()
        self.tor     = type(self.mgr1).__enter__(self.mgr1)
        self.mgr2    = self.tor.create_circuit(3)
        self.circuit = type(self.mgr2).__enter__(self.mgr2)
        self.mgr3    = self.circuit.create_stream((ip,port))
        self.stream  = type(self.mgr3).__enter__(self.mgr3)
    def send(self,data):
        self.stream.send(data)
    def recv(self,size):
        return self.stream.recv(size)
    def __del__(self):
        for bla in [self.mgr3,self.mgr2,self.mgr1]: type(bla).__exit__(bla, None, None, None)

Imagine an arbitrary software, replacing the two lines

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(server_data.server_address)

with the one-liner

client_socket = Torsocket(*server_data.server_address)

And the code works perfect before the replacement into torsocket.

What could be the source of the time-out-error then?

Also, how large is the network? Is your package creating a connection to the entire TOR network of the TOR project?
Or is this code building and residing on its own little twin? Because that might explain the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant