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

Periodically write a hostfile on the innernet server #336

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

@@ -338,6 +338,16 @@ impl DatabasePeer {
Ok(peer_iter.collect::<Result<_, _>>()?)
}

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.

@bschwind bschwind force-pushed the innernet-server-hostfile branch from e57ab94 to d8cc175 Compare March 13, 2025 05:27
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.

2 participants