예제 #1
0
static void
start_connect_task_relay (CloneTask *task, GError **error)
{
    CcnetPeer *peer = ccnet_get_peer (seaf->ccnetrpc_client, task->peer_id);
    if (!peer) {
        /* clone from a new relay */
        GString *buf = NULL; 
        seaf_message ("add relay before clone, %s:%s\n",
                      task->peer_addr, task->peer_port);
        buf = g_string_new(NULL);
        g_string_append_printf (buf, "add-relay --id %s --addr %s:%s",
                                task->peer_id, task->peer_addr, task->peer_port);
        ccnet_send_command (seaf->session, buf->str, NULL, NULL);
        transition_state (task, CLONE_STATE_CONNECT);
        g_string_free (buf, TRUE);
    } else {
        /* The peer is added to ccnet already and will be connected,
         * only need to transition the state
         */
        transition_state (task, CLONE_STATE_CONNECT);
    }

    if (peer)
        g_object_unref (peer);
}
예제 #2
0
파일: mainloop.c 프로젝트: andrey-str/ccnet
void ccnet_disconnect_peer (CcnetClient *client, const char *id)
{
    char buf[256];
    if (id == NULL || strlen(id) != 40)
        return;

    snprintf (buf, 256, "disconnect %s", id);
    ccnet_send_command (client, buf, NULL, NULL);
}
예제 #3
0
파일: mainloop.c 프로젝트: andrey-str/ccnet
/* add-peer [--id <peer-id>] [--addr <peer-addr:port>]
 */
void ccnet_add_peer (CcnetClient *client, const char *id, const char *addr)
{
    char buf[256];
    if (id == NULL || strlen(id) != 40 || addr == NULL)
        return;

    snprintf (buf, 256, "add-peer --id %s --addr %s", id, addr);
    ccnet_send_command (client, buf, NULL, NULL);
}
예제 #4
0
파일: sync-mgr.c 프로젝트: break123/seafile
/* In case ccnet relay info is lost(e.g. ~/ccnet is removed), we need to
 * re-add the relay by supplying addr:port
 */
static void
add_relay_if_needed (SeafRepo *repo)
{
    CcnetPeer *relay = NULL;
    char *relay_port = NULL, *relay_addr = NULL;
    GString *buf = NULL; 

    seaf_repo_manager_get_repo_relay_info (seaf->repo_mgr, repo->id,
                                           &relay_addr, &relay_port);

    relay = ccnet_get_peer (seaf->ccnetrpc_client, repo->relay_id);
    if (relay) {
        /* no relay addr/port info in seafile db. This means we are
         * updating from an old version. */
        if (!relay_addr || !relay_port) {
            if (relay->public_addr && relay->public_port) {
                char port[16];
                snprintf (port, sizeof(port), "%d", relay->public_port);
                seaf_repo_manager_set_repo_relay_info (seaf->repo_mgr, repo->id,
                                                       relay->public_addr, port);
            }
        }
        goto out;
    }

    /* relay info is lost in ccnet, but we have its addr:port in seafile.db */
    if (relay_addr && relay_port) {
        buf = g_string_new(NULL);
        g_string_append_printf (buf, "add-relay --id %s --addr %s:%s",
                                repo->relay_id, relay_addr, relay_port);
                                               
    } else {
        seaf_warning ("[sync mgr] relay addr/port info"
                      " of repo %.10s is unknown\n", repo->id);
    }

    if (buf) {
        ccnet_send_command (seaf->session, buf->str, NULL, NULL);
    }

out:
    g_free (relay_addr);
    g_free (relay_port);
    if (relay)
        g_object_unref (relay);
    if (buf)
        g_string_free (buf, TRUE);
}
예제 #5
0
파일: mainloop.c 프로젝트: andrey-str/ccnet
void
ccnet_register_service (CcnetClient *client,
                        const char *service,
                        const char *group,
                        GType proc_type,
                        RegisterServiceCB cb)
{
    char buf[512];
    g_return_if_fail (group);

    ccnet_proc_factory_register_processor (client->proc_factory, 
                                           service,
                                           proc_type);
    snprintf (buf, 512, "register-service %s %s", service, group);
    ccnet_send_command (client, buf, cmdrsp_cb, cb);
}