global group multicast

This commit is contained in:
云风
2012-08-30 23:31:33 +08:00
parent 161528e686
commit 1ee802c5c5
17 changed files with 285 additions and 40 deletions

View File

@@ -442,6 +442,19 @@ _remote_send_handle(struct harbor *h, struct skynet_context * context, uint32_t
return 0;
}
static void
_remote_register_name(struct harbor *h, struct skynet_context * context, const char name[GLOBALNAME_LENGTH], uint32_t handle) {
int i;
for (i=0;i<GLOBALNAME_LENGTH;i++) {
if (name[i] == '\0')
break;
}
if (handle != 0) {
_update_remote_name(h, context, name, handle);
}
_request_master(h,context,name,i,handle);
}
static int
_remote_send_name(struct harbor *h, struct skynet_context * context, uint32_t source, const char name[GLOBALNAME_LENGTH], int session, const char * msg, size_t sz) {
struct keyvalue * node = _hash_search(h->map, name);
@@ -457,23 +470,14 @@ _remote_send_name(struct harbor *h, struct skynet_context * context, uint32_t so
header.destination = 0;
header.session = (uint32_t)session;
_push_queue(node->queue, msg, sz, &header);
// 0 for request
_remote_register_name(h, context, name, 0);
return 1;
} else {
return _remote_send_handle(h, context, source, node->value, session, msg, sz);
}
}
static void
_remote_register_name(struct harbor *h, struct skynet_context * context, const char name[GLOBALNAME_LENGTH], uint32_t handle) {
int i;
for (i=0;i<GLOBALNAME_LENGTH;i++) {
if (name[i] == '\0')
break;
}
_update_remote_name(h, context, name, handle);
_request_master(h,context,name,i,handle);
}
static void
_report_local_address(struct harbor *h, struct skynet_context * context, const char * local_address, int harbor_id) {
size_t sz = strlen(local_address);

View File

@@ -220,6 +220,17 @@ _update_address(struct skynet_context * context, struct master *m, int harbor_id
}
m->remote_fd[harbor_id] = fd;
_broadcast(context, m, addr, sz, harbor_id);
int i;
for (i=1;i<REMOTE_MAX;i++) {
if (i == harbor_id)
continue;
const char * addr = m->remote_addr[i];
if (addr == NULL) {
continue;
}
_send_to(fd, addr, strlen(addr), i);
}
}

View File

@@ -0,0 +1,22 @@
#include "skynet.h"
#include <stdio.h>
static int
_cb(struct skynet_context * context, void * ud, int session, uint32_t source, const void * msg, size_t sz) {
uint32_t dest = (uint32_t)(uintptr_t)ud;
skynet_forward(context, dest);
return 0;
}
int
tunnel_init(void * dummy, struct skynet_context *ctx, const char * args) {
uint32_t dest = skynet_queryname(ctx, args);
if (dest == 0) {
skynet_error(ctx, "Can't create tunnel to %s",args);
return 1;
}
skynet_callback(ctx, (void*)(intptr_t)dest, _cb);
return 0;
}