first cut at supressing rhizome activity during calls.

This commit is contained in:
gardners 2012-05-22 13:05:29 +09:30
parent 4a3fc65385
commit 29bb86d9e7
7 changed files with 65 additions and 2 deletions

View File

@ -245,11 +245,15 @@ int overlay_payload_enqueue(int q,overlay_frame *p,int forceBroadcastP)
Complain if there are too many frames in the queue.
*/
if (q==OQ_ISOCHRONOUS_VOICE&&(!forceBroadcastP)) {
/* Dispatch voice data immediately. */
/* Dispatch voice data immediately.
Also tell Rhizome to back off a bit, so that voice traffic
can get through. */
int interface=-1;
int nexthoplen=SID_SIZE;
int broadcast=overlay_address_is_broadcast(p->destination);
rhizome_saw_voice_traffic();
overlay_abbreviate_clear_most_recent_address();
if (broadcast) {

View File

@ -369,3 +369,13 @@ int rhizome_hex_to_bytes(const char *in,unsigned char *out,int hexChars)
return 0;
}
/* When voice traffic is being carried, we need to throttle Rhizome down
to a more sensible level. Or possibly even supress it entirely.
*/
long long rhizome_voice_timeout=0;
int rhizome_saw_voice_traffic()
{
/* We are in "voice mode" for a second after sending a voice frame */
rhizome_voice_timeout=overlay_gettime_ms()+1000;
return 0;
}

View File

@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define RHIZOME_HTTP_PORT 4110
extern long long rhizome_voice_timeout;
typedef struct rhizome_http_request {
int socket;
long long last_activity; /* time of last activity in ms */

View File

@ -426,8 +426,22 @@ int rhizome_queue_manifest_import(rhizome_manifest *m,
return 0;
}
long long rhizome_last_fetch=0;
int rhizome_poll_fetchP=0;
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
{
/* Don't fetch quickly during voice calls */
rhizome_poll_fetchP=0;
long long now=overlay_gettime_ms();
if (now<rhizome_voice_timeout)
{
/* only fetch data once per 500ms during calls */
if ((rhizome_last_fetch+500)>now)
return 0;
}
rhizome_last_fetch=now;
rhizome_poll_fetchP=1;
int i;
if ((*fdcount)>=fdmax) return -1;
@ -451,10 +465,10 @@ int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
return 0;
}
int rhizome_fetch_poll()
{
int rn;
if (!rhizome_poll_fetchP) return 0;
if (debug&DEBUG_RHIZOME) WHYF("Checking %d active fetch requests",
rhizome_file_fetch_queue_count);
for(rn=0;rn<rhizome_file_fetch_queue_count;rn++)

View File

@ -131,6 +131,8 @@ int rhizome_server_start()
return 0;
}
int rhizome_poll_httpP=0;
int rhizome_server_poll()
{
struct sockaddr addr;
@ -138,6 +140,8 @@ int rhizome_server_poll()
int sock;
int rn;
if (!rhizome_poll_httpP) return 0;
/* Having the starting of the server here is helpful in that
if the port is taken by someone else, we will grab it fairly
swiftly once it becomes available. */
@ -255,10 +259,22 @@ int rhizome_server_free_http_request(rhizome_http_request *r)
return 0;
}
long long rhizome_last_http_send=0;
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
{
int i;
if ((*fdcount)>=fdmax) return -1;
rhizome_poll_httpP=0;
/* Don't send quickly during voice calls */
long long now=overlay_gettime_ms();
if (now<rhizome_voice_timeout)
{
/* only send data once per 500ms during calls */
if ((rhizome_last_http_send+500)>now)
return 0;
}
rhizome_last_http_send=now;
rhizome_poll_httpP=1;
if (rhizome_server_socket>-1)
{

View File

@ -73,6 +73,22 @@ int bundles_available=-1;
int bundle_offset[2]={0,0};
int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
{
int voice_mode=0;
/* behave differently during voice mode.
Basically don't encourage people to grab stuff from us, but keep
just enough activity going so that it is possible to send a (small)
message/file during a call.
XXX Eventually only advertise small/recently changed files during voice calls.
We need to change manifest table to include payload length to make our life
easy here (also would let us order advertisements by size of payload).
For now, we will just advertised only occassionally.
*/
long long now=overlay_gettime_ms();
if (now<rhizome_voice_timeout) voice_mode=1;
if (voice_mode) if (random()&3) return 0;
int pass;
int bytes=e->sizeLimit-e->length;
int overhead=1+8+1+3+1+1+1; /* maximum overhead */

View File

@ -1042,6 +1042,7 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now);
int overlay_route_please_advertise(overlay_node *n);
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
int rhizome_server_poll();
int rhizome_saw_voice_traffic();
int overlay_saw_mdp_containing_frame(int interface,overlay_frame *f,long long now);
#include "nacl.h"