Skip to content

Conversation

@bschwind
Copy link
Member

@bschwind bschwind commented Mar 3, 2025

Getting this started, spurred by a comment.

Related to #135 and #335

Right now this is implemented as a periodic tokio async task on the server when you run the serve command. I extracted the update_hosts_file() function from the client into the shared crate. That felt like the highest value location to add this functionality, though we could also add it to the various other server commands if we wish.

Beware, I haven't tested this yet at all.


pub fn list_enabled(conn: &Connection) -> Result<Vec<Self>, ServerError> {
let mut stmt = conn.prepare_cached(&format!(
"SELECT {} FROM peers WHERE peers.is_redeemed = 1 AND peers.is_disabled = 0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd just do a SELECT ip, name but the deserialization machinery is all in place to select the whole peer so I just went with that for now for convenience. Performance likely wouldn't be a problem unless you have a lot of peers.

@alerque
Copy link
Contributor

alerque commented Mar 4, 2025

If there is some expectation that this is pulled together enough to maybe work I'll give it a test drive.

@bschwind
Copy link
Member Author

bschwind commented Mar 4, 2025

@alerque I would recommend testing it by creating a new network with this server binary, adding a peer, then running the serve command to see if it writes to the hostfile. If you don't get to it I'll test it out later.

@alerque
Copy link
Contributor

alerque commented Mar 6, 2025

I have deployed e57ab94 on a production network by swapping out the system package for the last stable version (I am the Arch Linux packager for innernet) with an otherwise nearly identical package one built from this PR. I swapped out the package, restarted the server, and the /etc/hosts file and directs access to the innernet piers is working as expected! The catch of course is that things like innernet list <network> don't show anything at all and clients show it as innernet-server.<network.wg instead of what might be a preferred pier name. But having the current pier IP list in the hosts file is a huge improvement even without being a fully normalized member itself.

@bschwind
Copy link
Member Author

@alerque nice, thanks for testing! I'll see what I can do about the naming, but glad to hear it at least somewhat works.

Copy link
Member

@strohel strohel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for a late review - this looks good!

Initially I had a slight concern about 10 secs interval being a bit too low, but I see that we have an optimization that we don't write at all if the contents would be the same, so this boild to reading /etc/hosts every 10 secs, which is very fine.

Ship it, especially if this has already received testing.

@strohel strohel force-pushed the innernet-server-hostfile branch from d8cc175 to 252dc52 Compare August 7, 2025 08:33
@strohel
Copy link
Member

strohel commented Aug 7, 2025

Rebased on main to get a fresh CI run.

@mbernat
Copy link
Contributor

mbernat commented Aug 7, 2025

Tested that serve now writes into /etc/hosts. Let me know if you'd like to test something more specific; otherwise looks good to merge.

marek@Mareks-Laptop innernet % tail -n1 /etc/hosts

marek@Mareks-Laptop innernet % cargo build && sudo ./target/debug/innernet-server serve foo & 
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
[1] 16836
marek@Mareks-Laptop innernet % tail -n4 /etc/hosts
# DO NOT EDIT innernet foo BEGIN
10.47.0.1 innernet-server.foo.wg
10.47.64.1 marek.foo.wg
# DO NOT EDIT innernet foo END

@strohel
Copy link
Member

strohel commented Aug 7, 2025

@mbernat thanks for testing, that was is, merging.

@strohel strohel force-pushed the innernet-server-hostfile branch from 252dc52 to e820d4d Compare August 7, 2025 14:43
@strohel strohel enabled auto-merge (squash) August 7, 2025 14:43
@strohel strohel merged commit a3cd437 into main Aug 7, 2025
9 checks passed
@strohel strohel deleted the innernet-server-hostfile branch August 7, 2025 14:45
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.

5 participants