first cut code for sending monitor socket announcements when

rhizome bundles are received.
This commit is contained in:
gardners 2012-05-12 07:24:52 +09:30
parent cd65e47be1
commit 0b5a9665b2
3 changed files with 43 additions and 0 deletions

View File

@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "serval.h"
#include "rhizome.h"
#include <sys/stat.h>
#ifndef HAVE_STRUCT_UCRED
@ -511,6 +512,46 @@ int monitor_process_data(int index)
return 0;
}
int monitor_announce_bundle(rhizome_manifest *m)
{
int i;
char msg[1024];
snprintf(msg,1024,"\nBUNDLE:%s:%lld:%lld:%s\n",
/* XXX bit of a hack here, since SIDs and
cryptosign public keys have the same length */
overlay_render_sid(m->cryptoSignPublic),
m->version,
m->fileLength,
m->dataFileName?m->dataFileName:"");
for(i=0;i<monitor_socket_count;i++)
{
if (!(monitor_sockets[i].flags&MONITOR_RHIZOME))
continue;
nextInSameSlot:
errno=0;
fcntl(monitor_sockets[i].socket,F_SETFL,
fcntl(monitor_sockets[i].socket, F_GETFL, NULL)|O_NONBLOCK);
write(monitor_sockets[i].socket,msg,strlen(msg));
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
/* error sending update, so kill monitor socket */
WHYF("Tearing down monitor client #%d due to errno=%d",
i,errno);
close(monitor_sockets[i].socket);
if (i==monitor_socket_count-1) {
monitor_socket_count--;
continue;
} else {
bcopy(&monitor_sockets[monitor_socket_count-1],
&monitor_sockets[i],
sizeof(struct monitor_context));
monitor_socket_count--;
goto nextInSameSlot;
}
}
}
return 0;
}
int monitor_call_status(vomp_call_state *call)
{
int i;

View File

@ -276,6 +276,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
if (rhizome_store_bundle(m_in, filename) == -1)
return WHY("rhizome_store_bundle() failed.");
monitor_announce_bundle(m_in);
if (m_out) *m_out = m_in;
return 0;
}

View File

@ -227,3 +227,4 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath);
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
int rhizome_manifest_version_cache_lookup(rhizome_manifest *m);
int rhizome_manifest_version_cache_store(rhizome_manifest *m);
int monitor_announce_bundle(rhizome_manifest *m);