Skip to content

Commit b2897a5

Browse files
authored
Merge pull request #1695 from stratosphereips/alya/fix_p2p_bin_unable_to_connect_to_redis
Fix P2P pigeon unable to connect to the redis database given to it by slips.
2 parents 1d66d70 + af3c58b commit b2897a5

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

fides

Submodule fides updated from 8492d6c to 7065774

modules/p2ptrust/p2ptrust.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
Direction,
2828
)
2929

30+
LOCALHOST = "127.0.0.1"
31+
3032

3133
def validate_slips_data(message_data: str) -> (str, int):
3234
"""
@@ -197,30 +199,23 @@ def _configure(self):
197199
f"Did you include it in PATH?. Exiting process."
198200
)
199201
return
200-
executable = [self.pigeon_binary]
201-
port_param = ["-port", str(self.port)]
202-
# if '-ip' in sys.argv:
203-
# ip_to_listen_on = sys.argv[sys.argv.index('-ip')+1]
204-
# host_param = ["-host", ip_to_listen_on ]
205-
# print(f"P2P modules is listening on ip {ip_to_listen_on} port: {self.port}, using '-ip' parameter")
206-
# else:
207-
host_param = ["-host", self.host]
202+
203+
params = {
204+
"-port": str(self.port),
205+
"-host": self.host,
206+
"-key-file": self.pigeon_key_file,
207+
"--redis-db": f"localhost:{self.redis_port}",
208+
"-redis-channel-pygo": self.pygo_channel_raw,
209+
"-redis-channel-gopy": self.gopy_channel_raw,
210+
}
208211
self.print(
209-
f"P2p is listening on {self.host} port {self.port} determined "
210-
f"by p2p module"
212+
f"P2P is listening on {self.host} port {self.port} "
213+
f"(determined by p2p module)"
211214
)
215+
executable = [self.pigeon_binary] + [
216+
item for pair in params.items() for item in pair
217+
]
212218

213-
keyfile_param = ["-key-file", self.pigeon_key_file]
214-
# rename_with_port_param = ["-rename-with-port",
215-
# str(self.rename_with_port).lower()]
216-
pygo_channel_param = ["-redis-channel-pygo", self.pygo_channel_raw]
217-
gopy_channel_param = ["-redis-channel-gopy", self.gopy_channel_raw]
218-
executable.extend(port_param)
219-
executable.extend(host_param)
220-
executable.extend(keyfile_param)
221-
# executable.extend(rename_with_port_param)
222-
executable.extend(pygo_channel_param)
223-
executable.extend(gopy_channel_param)
224219
if self.create_p2p_logfile:
225220
outfile = open(self.pigeon_logfile, "+w")
226221
else:
@@ -649,7 +644,7 @@ def main(self):
649644
# give the pigeon time to put the multiaddr in the db
650645
time.sleep(2)
651646
multiaddr = self.db.get_multiaddr()
652-
self.print(f"You Multiaddress is: {multiaddr}")
647+
self.print(f"You Multiaddress is: {multiaddr}\n")
653648
self.mutliaddress_printed = True
654649

655650
except Exception:

p2p4slips

Submodule p2p4slips updated 1 file

slips_files/core/database/redis_db/database.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131

3232
RUNNING_IN_DOCKER = os.environ.get("IS_IN_A_DOCKER_CONTAINER", False)
33+
LOCALHOST = "127.0.0.1"
3334

3435

3536
class RedisDB(IoCHandler, AlertHandler, ProfileHandler, P2PHandler):
@@ -332,7 +333,7 @@ def _confirm_redis_is_listening(cls, timeout: float = 5.0) -> (bool, str):
332333
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
333334
sock.settimeout(0.2)
334335
try:
335-
sock.connect(("127.0.0.1", cls.redis_port))
336+
sock.connect((LOCALHOST, cls.redis_port))
336337
return True, "" # Redis is up
337338
except (ConnectionRefusedError, OSError):
338339
time.sleep(0.2)
@@ -348,7 +349,7 @@ def _start_a_redis_server(cls) -> bool:
348349
cmd = (
349350
f"redis-server {cls._conf_file} "
350351
f"--port {cls.redis_port} "
351-
f"--bind 127.0.0.1 "
352+
f"--bind {LOCALHOST} "
352353
f"--daemonize yes"
353354
)
354355
process = subprocess.Popen(
@@ -942,7 +943,7 @@ def should_store_resolution(
942943
# don't store this as a valid dns resolution
943944
if query != "localhost":
944945
for answer in answers:
945-
if answer in ("127.0.0.1", "0.0.0.0"):
946+
if answer in (LOCALHOST, "0.0.0.0"):
946947
return False
947948

948949
return True
@@ -1262,7 +1263,8 @@ def get_ip_identification(
12621263

12631264
def get_multiaddr(self):
12641265
"""
1265-
this is can only be called when p2p is enabled, this value is set by p2p pigeon
1266+
this can only be called when p2p is enabled,
1267+
this value is set by p2p pigeon in the db
12661268
"""
12671269
return self.r.get(self.constants.MULTICAST_ADDRESS)
12681270

0 commit comments

Comments
 (0)