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

Feat/ip from server #272

Merged
merged 14 commits into from
Jul 10, 2024
Merged

Feat/ip from server #272

merged 14 commits into from
Jul 10, 2024

Conversation

ersonp
Copy link
Contributor

@ersonp ersonp commented Jul 8, 2024

Fixes #

Changes:

  • Added new method DailServerForIP
  • Added cmd tool dmsgip

How to test this PR:

  1. make build
  2. ./bin/dmsgip -c <skywire-discovery> -d <dmsgserver pk>

to test against an old dmsg server run:

  1. ./bin/dmsgip

This commit adds a new method `DialServerForIP` to the `Client` struct in the `pkg/dmsg/client.go` file. This method dials to dmsg servers to retrieve the public IP address of the client. It iterates through a list of server entries, attempts to dial each server, and returns the first public IP address it receives.

The purpose of this change is to provide a way for the client to obtain its public IP address from dmsg servers.
This commit modifies the `DialServerForIP` method in the `pkg/dmsg/client.go` file to accept a slice of dmsg server public keys as an argument. If the `servers` argument is nil, the method retrieves the server entries using the `discoverServers` function and populates the `servers` slice with the static public keys from the entries. Then, it iterates through the `servers` slice and attempts to dial each server to retrieve the public IP address of the client.

The purpose of this change is to allow the `DialServerForIP` method to support custom dmsg server public keys, providing more flexibility in obtaining the client's public IP address from dmsg servers.
@0pcom
Copy link
Collaborator

0pcom commented Jul 9, 2024

$ go run cmd/dmsgip/dmsgip.go --loglvl debug
[2024-07-09T13:35:15.286441301-05:00] DEBUG disc.NewHTTP [dmsgip]: Created HTTP client. addr="http://dmsgd.skywire.dev"
[2024-07-09T13:35:15.286491615-05:00] DEBUG [dmsgip]: Connecting to dmsg network... dmsg_disc="http://dmsgd.skywire.dev" public_key="03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed"
[2024-07-09T13:35:15.286527793-05:00] DEBUG [dmsg_client]: Discovering dmsg servers...
[2024-07-09T13:35:15.554175163-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:35:16.091536741-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2024-07-09T13:35:16.091587389-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:35:16.091556741-05:00] DEBUG [dmsgip]: Dmsg network ready.
[2024-07-09T13:35:16.511994419-05:00] DEBUG [dmsg_client]: Updating entry. entry=	version: 0.0.1
	sequence: 0
	registered at: 1720550115957254681
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: eaaa9eafd7fe7ed434a98e940b837af9c234b74695afce5d2e0be7c6a4925882620d1b17310638f29b93ccab0aedee4459361d6a820dafe65b36d9577a51ad4500
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd


[2024-07-09T13:35:16.646907647-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:35:16.646987668-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2024-07-09T13:35:17.188558338-05:00] DEBUG [dmsg_client]: Updating entry. entry=	version: 0.0.1
	sequence: 1
	registered at: 1720550116512094519
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: c7842d47c3f041b51db1e81981ddc5e09795f07691a6d8352d5988db1ebfb9bb7496610a118a2a761cbb5621f52de0e0e69194b3828fa5b80e50f6b3502bf55201
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
			0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13


[2024-07-09T13:35:17.332330435-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2024-07-09T13:35:17.332455829-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:35:17.610919987-05:00] DEBUG [dmsg_client]: Updating entry. entry=	version: 0.0.1
	sequence: 2
	registered at: 1720550117188623816
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: 86652bb716077103e7bf4f46bc47fbf3485428e11e394e01f03b83f2d61b60e770a91d0862434d1d73cd7d3a0117cd7dcefe318e8ba2aad911446ff17114d3f800
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
			0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
			0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7


[2024-07-09T13:35:17.749076613-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
[2024-07-09T13:35:17.749194938-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2024-07-09T13:35:18.283417658-05:00] DEBUG [dmsg_client]: Updating entry. entry=	version: 0.0.1
	sequence: 3
	registered at: 1720550117611047539
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: 15e80c59e8bf4c80a9ad533d51414e23e72f07eb95447603baaacdc87e1c2be26806f444a40973683bf0a916cb1ce1a0cb57de7039d399f5efd814482aad3c3c00
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
			0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
			0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
			0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb


[2024-07-09T13:35:18.41683289-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4
[2024-07-09T13:35:18.416909854-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
[2024-07-09T13:35:18.966509833-05:00] DEBUG [dmsg_client]: Updating entry. entry=	version: 0.0.1
	sequence: 4
	registered at: 1720550118283465270
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: 9825596559bbcf3be6d6b484975b3a2e3b80420da2fb1ef5f756466d46e09b5a29be49b7384c4f0555065b8eeebdcccccb5ab24a3a469cae0a64eadb2f79749c00
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
			0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
			0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
			0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
			03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4


[2024-07-09T13:35:19.104340159-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4
[2024-07-09T13:35:36.365913992-05:00] DEBUG ClientSession.DialServerForIP [dmsg_client]: Stream closed on failure. close_error=<nil> dst_addr=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0 error="i/o deadline reached" session=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:35:36.365988065-05:00] WARN [dmsg_client]: Failed to dial server for IP. error="i/o deadline reached" server_pk=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:35:56.367253148-05:00] DEBUG ClientSession.DialServerForIP [dmsg_client]: Stream closed on failure. close_error=<nil> dst_addr=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13 error="i/o deadline reached" session=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:35:56.367332137-05:00] WARN [dmsg_client]: Failed to dial server for IP. error="i/o deadline reached" server_pk=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:36:15.30320242-05:00] DEBUG [dmsg_client]: Discovering dmsg servers...
[2024-07-09T13:36:15.562997493-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2024-07-09T13:36:15.563041012-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:36:15.563060042-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:36:15.563075216-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4
[2024-07-09T13:36:15.563099998-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
[2024-07-09T13:36:15.563128049-05:00] DEBUG [dmsg_client]: Session already exists... remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2024-07-09T13:36:16.368331463-05:00] DEBUG ClientSession.DialServerForIP [dmsg_client]: Stream closed on failure. close_error=<nil> dst_addr=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd error="i/o deadline reached" session=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2024-07-09T13:36:16.368430503-05:00] WARN [dmsg_client]: Failed to dial server for IP. error="i/o deadline reached" server_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd

ip address was returned here ; omitted from this logging

<ip-address>[2024-07-09T13:36:16.377864066-05:00] DEBUG [dmsg_client]: Stopped serving client!
[2024-07-09T13:36:16.377882347-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.377903493-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
[2024-07-09T13:36:16.377939247-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2024-07-09T13:36:16.377965148-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.378017863-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2024-07-09T13:36:16.378030643-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.3780717-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.378093927-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2024-07-09T13:36:16.37809813-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
[2024-07-09T13:36:16.378122316-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.378158375-05:00] DEBUG [dmsg_client]: Session closed. error=<nil>
[2024-07-09T13:36:16.378168218-05:00] DEBUG [dmsg_client]: All sessions closed.
[2024-07-09T13:36:16.378168593-05:00] DEBUG [dmsg_client]: Stopped accepting streams. error="session shutdown" session=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4
[2024-07-09T13:36:16.517990153-05:00] DEBUG [dmsg_client]: Deleting entry. entry=	version: 0.0.1
	sequence: 5
	registered at: 1720550118966582545
	static public key: 03e4fd341c53f16f91210b4dd781c22293c46d6bfc508ecd4a15d5504d524578ed
	signature: d085e772eb5c4dca678b5ab19dd4f06d212d57c2bbfd2b66804d06240b2780312534f58c7e9f014490daa192f23cae8fb2183b890cd88e2d51431849243fbd6300
	entry is registered as client. Related info: 
		delegated servers: 
			02a49bc0aa1b5b78f638e9189be4ed095bac5d6839c828465a8350f80ac07629c0
			02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
			0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
			0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
			0281a102c82820e811368c8d028cf11b1a985043b726b1bcdb8fce89b27384b2cb
			03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4


[2024-07-09T13:36:16.650405853-05:00] DEBUG [dmsg_client]: Entry Deleted successfully.
[2024-07-09T13:36:16.650465123-05:00] DEBUG [dmsgip]: Disconnected from dmsg network. error=<nil>


ersonp added 10 commits July 10, 2024 13:10
…rIP method

This commit refactors the `DialServerForIP` method in the `pkg/dmsg/client.go` file to improve error handling and connection logic. It introduces two separate loops to handle delegated servers and attempts to connect to each server individually. Additionally, it properly closes if the session is created just for the IP after dialing the server.

The purpose of this change is to enhance the reliability and stability of the `DialServerForIP` method when retrieving the public IP address from dmsg servers.
This commit renames the `DialServerForIP` method to `LookupIP` in the `pkg/dmsg/client.go` file. The functionality remains the same, but the new name better reflects the purpose of the method, which is to lookup the public IP address of the client from dmsg servers.

The purpose of this change is to improve the clarity and consistency of the method name, making it more intuitive for developers working with the dmsg client.
This commit updates the IP lookup logic in the `stream_test.go` file. It introduces conditional checks based on the operating system to handle different IP address formats. On Windows, the IP address is expected to be "127.0.0.1", while on other operating systems, it is expected to be "::1".

The purpose of this change is to ensure that the IP lookup tests pass correctly on different operating systems, improving the reliability and consistency of the test suite.
@0pcom 0pcom merged commit c1a367e into skycoin:develop Jul 10, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants