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

unbootstrap #2733

Open
og1en opened this issue Mar 9, 2024 · 16 comments
Open

unbootstrap #2733

og1en opened this issue Mar 9, 2024 · 16 comments
Milestone

Comments

@og1en
Copy link

og1en commented Mar 9, 2024

I need turn off network but not destroy tox structure. I need turn on/off network many times in my program, not only one.
How turn off automatic reconecting network ?

@iphydf iphydf added this to the v0.2.19 milestone Mar 9, 2024
@Green-Sky
Copy link
Member

You cant. You will have to destroy the tox object to be offline, and when you want to come online again you have to recreate it.

You can try using TCP only, as this might reduce traffic. Also NewGroupChats support disconnecting without destroying its state.

@nurupo
Copy link
Member

nurupo commented Mar 9, 2024

If you want to go offline without destroying the Tox instance, simply stop calling tox_iterate(), which does all the Tox logic. Your Tox instance would stop all the processing and responding to network requests, so to others it would seem as if you suddenly lost the Internet connection and you will eventually time out and be shown as offline on their end.

If you want to go offline immediately however, without others still seeing you as being online until some timeout amount of time passes on their end, the Tox instance would need to send packets to others telling that it's shutting down, which is done only when the Tox instance is destroyed, there is no option to send those without destroying it. What you can do in this case to still access the Tox struct is re-create it back after destroying it but with network settings that prevent it from connecting to anything. So before you destroy the Tox instance you would call tox_get_savedata() to save its state, then destroy the Tox instance, then create a new Tox instance off the saved state, with UDP and LAN discovery options disabled and a bogus proxy that Tox would fail to connect to specified, avoiding calling any bootstrap/add_tcp_relay function calls as that would be pointless without a network.

@fab1an2
Copy link

fab1an2 commented Mar 11, 2024

Tox struct is re-create it back after destroying it but with network settings that
prevent it from connecting to anything.

Can You explain? what options?

It seems that such a feature is indeed missing and would be worth adding. Go offline mode. Just not using the main loop is not elegant or fast. Besides, you still have open ports and may be charged for Internet usage. Especially painful when roaming.

@Green-Sky
Copy link
Member

Green-Sky commented Mar 11, 2024

Just not using the main loop is not elegant or fast. Besides, you still have open ports and may be charged for Internet usage.

The "don't call iterate()" option seems to be the easiest one. Open ports should not get you charged anything by themself, since the ports are local. But eg your friends who keep pinging you until you timeout might cause you traffic. Not calling iterate() or any send*() function should be good for the long run though.

@iphydf
Copy link
Member

iphydf commented Mar 11, 2024

Why do you need the Tox structure to not be destroyed?

@zoff99
Copy link

zoff99 commented Mar 15, 2024

@og1en can you please give more details? are you using a tox client? if so which one?
or are you developing your own program using the toxcore library?

if so, as mentioned, when you stop calling tox_iterate() in your code then tox will not do any networking activity anymore (connections will timeout).

automatic reconnecting and bootstrapping is only done in tox clients.

@iphydf iphydf modified the milestones: v0.2.19, v0.2.20 Mar 25, 2024
@iphydf
Copy link
Member

iphydf commented Mar 25, 2024

@fab1an2 I see you 👎 my question. Was it a bad question? I'm trying to understand how to solve the problem.

@fab1an2

This comment was marked as off-topic.

@iphydf
Copy link
Member

iphydf commented Mar 26, 2024

The requirements I see so far are:

  1. Keep the Tox structure alive.
  2. Close all network ports (and thus sockets).
  3. Notify other clients quickly about your going offline.
  4. (maybe?) Quickly reconnect to the network when going back online.

The 4th requirement means you will need to reopen those ports/sockets and rebuild the network connections, which will take around 10 seconds (regular bootstrap). Overall, you can achieve everything except 1) by doing tox_get_savedata (which stores some DHT endpoints so it can quickly bootstrap back into the network), then tox_kill (closes sockets and tells clients about going offline), and then tox_new with the saved DHT nodes.

So the question remains: why do you want the struct to remain alive?

An alternative question might be, since you're looking for a feature to be added to toxcore: do you want a function in toxcore that implements the method I described above?

@og1en
Copy link
Author

og1en commented Mar 27, 2024

I'm not undestand what 4. point will be.
For me important is only 1 and 2 point.

I pay for open ports, for something being sent over the network, etc.

I would like my program to be able to create messages but not send them. Just like thunderbird https://www.thunderbird.net/ . I can write a dozen emails and only when I have the network on, or when I realistically hit the exchange button only then do I send and receive data. And so I can quietly turn on the program, write data.

I do not need to inform that I change the status to busy. Although it is possible. It is just that for me it is not the most important thing. I simply want to disable the network plug from the wall for this particular program. Go offline but still be able to write messages and read them.

{
create_tox();
atexit(koniec_tox());

while(not_end)
  {
  <bootstrap(....)>
  <send-receive messages>
  <unbootstrap(....) or similar>
  }


 tox_kill(tox);
}

@JFreegman
Copy link
Member

JFreegman commented Mar 27, 2024

I would like my program to be able to create messages but not send them. Just like thunderbird https://www.thunderbird.net/ . I can write a dozen emails and only when I have the network on, or when I realistically hit the exchange button only then do I send and receive data. And so I can quietly turn on the program, write data.

You don't need to disconnect from the tox network to achieve this. You can simply write a message queue that holds your messages until your trigger condition, then batch sends them. Your trigger condition could be a manual button that you click, or it could be upon detection that the message's respective contact has come online.

@iphydf
Copy link
Member

iphydf commented Mar 27, 2024

Tox does not store sent messages permanently. In particular, if you are not online or your friend is not online, you can't send messages through toxcore. If you send a message when the friend appears online, but they don't actually receive it (e.g. network issues), then toxcore will drop the message on the floor (you don't get a delivery receipt then).

It sounds like what you want is a storage to put messages in until you're online and able to send them all in a batch. This is something usually implemented in clients rather than in toxcore. If you want to close network sockets, then tox_kill will do that for you.

Given that Toxcore is not able to enqueue messages when offline, is there a reason to keep the struct alive even when offline?

@nurupo
Copy link
Member

nurupo commented Mar 27, 2024

I pay for open ports, for something being sent over the network, etc.

Is it like VPN port forwarding, where the VPN service assigns you an open TCP port to use? If so, depending on how the service you use exactly works, you might not need to open any ports as Tox does NAT hole-punching, and in the case that doesn't work, you could use a TCP relay.

I would like my program to be able to create messages but not send them. Just like thunderbird https://www.thunderbird.net/ .

Just want to make sure you understand that Tox doesn't work like email. Tox doesn't support offline/asynchronous messaging. For your messages to be sent, both the sender and the receiver have to be online at the same time. Sender sends messages directly to the receiver, there is no intermediary that will hold sender's messages and relay them to the receiver once they are online. If the receiver or the sender (or both) are offline, no message can be sent or received.

I can write a dozen emails and only when I have the network on, or when I realistically hit the exchange button only then do I send and receive data.

Toxcore won't let you queue up messages to be sent while you or the receiver are offline, it's designed to send the messages right away. If you need such a message queue, that's something you have implement on top of Toxcore in your own code.

@fab1an2

This comment was marked as off-topic.

@fab1an2

This comment was marked as off-topic.

@nurupo

This comment was marked as off-topic.

@iphydf iphydf modified the milestones: v0.2.20, v0.2.21 Nov 6, 2024
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

7 participants