Ejemplo n.º 1
0
static gboolean _torControlCircuitBuild_initialize(gpointer moduleData) {
    TorCtlCircuitBuild *circuitBuild = moduleData;
    ShadowLogFunc log = circuitBuild->log;

    gint sockd = circuitBuild->sockd;
    gboolean initialized = 0;

    if(circuitBuild->waitingForResponse) {
        return 0;
    }

    switch(circuitBuild->state) {
        case TORCTL_CIRCBUILD_STATE_AUTHENTICATE: {
            /* authenticate with the control */
            if(torControl_authenticate(sockd, "password") > 0) {
                circuitBuild->nextState = TORCTL_CIRCBUILD_STATE_SETCONFS;
                circuitBuild->waitingForResponse = TRUE;
            }
            break;
        }

        case TORCTL_CIRCBUILD_STATE_SETCONFS: {
            /* set configuration variables */
            gchar *confValues[7] = {"__LeaveStreamsUnattached", "1", "ExcludeSingleHopRelays", "0", "AllowSingleHopCircuits", "1", NULL};
            if(torControl_setconf(sockd, confValues) > 0) {
                circuitBuild->nextState = TORCTL_CIRCBUILD_STATE_SETEVENTS;
                circuitBuild->waitingForResponse = TRUE;
            }
            break;
        }

        case TORCTL_CIRCBUILD_STATE_SETEVENTS: {
            /* send list of events to listen on */
            if(torControl_setevents(sockd, "CIRC STREAM STATUS_CLIENT") > 0) {
                circuitBuild->nextState = TORCTL_CIRCBUILD_STATE_CHECKSTATUS;
                circuitBuild->waitingForResponse = TRUE;
            }
            break;
        }

        case TORCTL_CIRCBUILD_STATE_CHECKSTATUS: {
            /* check the bootstrap status of the node */
            if(torControl_getInfoBootstrapStatus(sockd) > 0) {
                circuitBuild->nextState = TORCTL_CIRCBUILD_STATE_CREATE_CIRCUIT;
                circuitBuild->waitingForResponse = TRUE;
                initialized = TRUE;
            }
            break;
        }

        case TORCTL_CIRCBUILD_STATE_CREATE_CIRCUIT:
        case TORCTL_CIRCBUILD_STATE_GET_CIRC_ID:
        case TORCTL_CIRCBUILD_STATE_ATTACH_STREAMS:
        	break;
    }

    return initialized;
}
Ejemplo n.º 2
0
static gboolean _torcontrollogger_manageState(TorControlLogger* tcl) {

	beginmanage: switch (tcl->currentState) {

	case TCS_SEND_AUTHENTICATE: {
		/* authenticate with the control port */
		if (torControl_authenticate(tcl->targetSockd, "password") > 0) {
			/* idle until we receive the response, then move to next state */
			tcl->currentState = TCS_IDLE;
			tcl->nextState = TCS_RECV_AUTHENTICATE;
		}
		break;
	}

	case TCS_RECV_AUTHENTICATE: {
		tcl->currentState = TCS_SEND_SETEVENTS;
		goto beginmanage;
		break;
	}

	case TCS_SEND_SETEVENTS: {
		/* send list of events to listen on */
		GString* events = g_string_new("CIRC STREAM ORCONN BW STREAM_BW CIRC_MINOR BUILDTIMEOUT_SET CLIENTS_SEEN GUARD");
		if (torControl_setevents(tcl->targetSockd, events->str) > 0) {
			/* idle until we receive the response, then move to next state */
			tcl->currentState = TCS_IDLE;
			tcl->nextState = TCS_RECV_SETEVENTS;
			tcl->log(G_LOG_LEVEL_CRITICAL, __FUNCTION__, "set tor control events '%s'", events->str);
		}
		g_string_free(events, TRUE);
		break;
	}

	case TCS_RECV_SETEVENTS: {
		/* all done */
		tcl->currentState = TCS_IDLE;
		tcl->nextState = TCS_IDLE;
		goto beginmanage;
		break;
	}

	case TCS_IDLE: {
		if (tcl->nextState == TCS_IDLE) {
			return TRUE;
		}
		break;
	}

	default:
		break;
	}

	return FALSE;
}
static gboolean _torcontrollogger_manageState(TorControlLogger* tcl) {

	beginmanage: switch (tcl->currentState) {

	case TCLS_SEND_AUTHENTICATE: {
		/* authenticate with the control port */
		if (torControl_authenticate(tcl->targetSockd, "password") > 0) {
			/* idle until we receive the response, then move to next state */
			tcl->currentState = TCLS_IDLE;
			tcl->nextState = TCLS_RECV_AUTHENTICATE;
		}
		break;
	}

	case TCLS_RECV_AUTHENTICATE: {
		tcl->currentState = TCLS_SEND_SETEVENTS;
		goto beginmanage;
		break;
	}

	case TCLS_SEND_SETEVENTS: {
		/* send list of events to listen on */
		if (torControl_setevents(tcl->targetSockd, tcl->torctlEvents) > 0) {
			/* idle until we receive the response, then move to next state */
			tcl->currentState = TCLS_IDLE;
			tcl->nextState = TCLS_RECV_SETEVENTS;
			tcl->log(SHADOW_LOG_LEVEL_MESSAGE, __FUNCTION__, "set tor control events '%s'", tcl->torctlEvents);
		}
		break;
	}

	case TCLS_RECV_SETEVENTS: {
		/* all done */
		tcl->currentState = TCLS_IDLE;
		tcl->nextState = TCLS_IDLE;
		goto beginmanage;
		break;
	}

	case TCLS_IDLE: {
		if (tcl->nextState == TCLS_IDLE) {
			return TRUE;
		}
		break;
	}

	default:
		break;
	}

	return FALSE;
}