/* * TransmitQueryInterface assembles a control query interface packet and initializes the transmit procedure * * Params: * acktype specifies host or client as well as failure or success * host_interface is the interface which belongs to the host of the query * result is the resultant interface id which is relevent only when acktype is host_end(SUCCESS) * mux is the MUX object the data is to be transmitted through */ int32 TransmitQueryInterface (int8 acktype, int8 host_interface, int8 result, sint8* name, MUX* mux) { COMMBUFF* commbuff; QUERYINTERFACE_PACKET* packetdata; int32 namesize; DEBUG("TransmitQueryInterface(%lu, %lu, %lu, %p, %p)\n", (int32)acktype, (int32)host_interface, (int32)result, name, mux); if(name) namesize = strlen((char*)name)+1; else namesize = 0; if(namesize > PACKET_MAXNAME_LENGTH) return DEBUGERROR(ERROR_INVALIDPARAMETER); commbuff = int_alloc_commbuff(sizeof(QUERYINTERFACE_PACKET)); packetdata = (QUERYINTERFACE_PACKET*)commbuff_data(commbuff); packetdata->type = PACKETTYPE_QUERYINTERFACE; commbuff_copyin_byte(commbuff, offsetof(QUERYINTERFACE_PACKET, acktype), acktype); commbuff_copyin_byte(commbuff, offsetof(QUERYINTERFACE_PACKET, host_interface), host_interface); commbuff_copyin_byte(commbuff, offsetof(QUERYINTERFACE_PACKET, result), result); commbuff_copyin(commbuff, offsetof(QUERYINTERFACE_PACKET, name), name, namesize); queue_commbuff(commbuff, &mux->send_queue); mux->total_queued_amount += sizeof(QUERYINTERFACE_PACKET); task_schedule(&mux->send_task); return DEBUGERROR(ERROR_NONE); }
/* * TransmitChannelSignal transmits a four int8 value to the channel * * Params: * acktype specifies host or client as well as failure or success * channel is the channel to be signaled * signal is the value to be delivered * mux is the MUX object the data is to be transmitted through */ int32 TransmitChannelSignal(int8 acktype, int8 channel, int32 signal, MUX *mux) { COMMBUFF *commbuff; CHANNELSIGNAL_PACKET *packetdata; DEBUG("TransmitChannelSignal(%lu, %lu, %lu, %p)\n", (int32) acktype, (int32) channel, signal, mux); commbuff = int_alloc_commbuff(sizeof(CHANNELSIGNAL_PACKET)); packetdata = (CHANNELSIGNAL_PACKET *) commbuff_data(commbuff); packetdata->type = PACKETTYPE_CHANNELSIGNAL; commbuff_copyin_byte(commbuff, offsetof(CHANNELSIGNAL_PACKET, acktype), acktype); commbuff_copyin_byte(commbuff, offsetof(CHANNELSIGNAL_PACKET, channel), channel); commbuff_copyin_dword(commbuff, offsetof(CHANNELSIGNAL_PACKET, signal), signal); queue_commbuff(commbuff, &mux->send_queue); mux->total_queued_amount += sizeof(CHANNELSIGNAL_PACKET); task_schedule(&mux->send_task); return DEBUGERROR(ERROR_NONE); }
static void report_error (NCDUdevMonitor *o) { ASSERT(!o->process_running) ASSERT(!o->input_running) DEBUGERROR(&o->d_err, o->handler_error(o->user, (o->process_was_error || o->input_was_error))); }
/* * TransmitCredit assembles a control credit packet and initializes the transmit procedure * * Params: * acktype specifies host or client as well as failure or success * channel is the channel the credit should be applied to * bytecredit is the amount the byte credit should be increased * sendcredit is the amount the send credit should be increased * mux is the MUX object the data is to be transmitted through */ int32 TransmitCredit (int8 acktype, int8 channel, int32 bytecredit, int32 sendcredit, MUX* mux) { COMMBUFF* commbuff; CREDIT_PACKET* packetdata; DEBUG( "TransmitCredit(%lu, %lu, %lu, 0x%lu, %p)\n", (int32)acktype, (int32)channel, (int32)bytecredit, (int32)sendcredit, mux ); commbuff = int_alloc_commbuff(sizeof(CREDIT_PACKET)); convert_dword(bytecredit); convert_dword(sendcredit); packetdata = (CREDIT_PACKET*)commbuff_data(commbuff); packetdata->type = PACKETTYPE_CREDIT; commbuff_copyin_byte(commbuff, offsetof(CREDIT_PACKET, acktype), acktype); commbuff_copyin_byte(commbuff, offsetof(CREDIT_PACKET, channel), channel); commbuff_copyin_dword(commbuff, offsetof(CREDIT_PACKET, bytecredit), bytecredit); commbuff_copyin_dword(commbuff, offsetof(CREDIT_PACKET, sendcredit), sendcredit); queue_commbuff(commbuff, &mux->send_queue); mux->total_queued_amount += sizeof(CREDIT_PACKET); task_schedule(&mux->send_task); return DEBUGERROR(ERROR_NONE); }
/* * TransmitDisableChannel assembles a control disable channel packet and initializes the transmit procedure * * Params: * acktype specifies host or client as well as failure or success * channel is the channel to be disabled * host_interface is the interface which belongs to the host and is requesting the disable * client_interface is the interface which belongs to the client and is responding to the disable * mux is the MUX object the data is to be transmitted through */ int32 TransmitDisableChannel (int8 acktype, int8 channel, int8 host_interface, int8 client_interface, MUX* mux) { COMMBUFF* commbuff; DISABLECHANNEL_PACKET* packetdata; DEBUG("TransmitDisableChannel(%lu, %lu, %lu, %lu, %p)\n", (int32)acktype, (int32)channel, (int32)host_interface, (int32)client_interface, mux); commbuff = int_alloc_commbuff(sizeof(DISABLECHANNEL_PACKET)); packetdata = (DISABLECHANNEL_PACKET*)commbuff_data(commbuff); packetdata->type = PACKETTYPE_DISABLECHANNEL; commbuff_copyin_byte(commbuff, offsetof(DISABLECHANNEL_PACKET, acktype), acktype); commbuff_copyin_byte(commbuff, offsetof(DISABLECHANNEL_PACKET, channel), channel); commbuff_copyin_byte(commbuff, offsetof(DISABLECHANNEL_PACKET, host_interface), host_interface); commbuff_copyin_byte(commbuff, offsetof(DISABLECHANNEL_PACKET, client_interface), client_interface); queue_commbuff(commbuff, &mux->send_queue); mux->total_queued_amount += sizeof(DISABLECHANNEL_PACKET); task_schedule(&mux->send_task); return DEBUGERROR(ERROR_NONE); }
static void report_error (BDatagram *o) { DebugError_AssertNoError(&o->d_err); // report error DEBUGERROR(&o->d_err, o->handler(o->user, BDATAGRAM_EVENT_ERROR)); return; }
static void connection_report_error (BConnection *o) { DebugError_AssertNoError(&o->d_err); ASSERT(o->handler) // report error DEBUGERROR(&o->d_err, o->handler(o->user, BCONNECTION_EVENT_ERROR)); return; }
static void dgram_handler (BArpProbe *o, int event) { DebugObject_Access(&o->d_obj); BLog(BLOG_ERROR, "packet socket error"); // report error DEBUGERROR(&o->d_err, o->handler(o->user, BARPPROBE_EVENT_ERROR)); return; }
static void input_handler_done (SingleStreamReceiver *o, int data_len) { DebugObject_Access(&o->d_obj); ASSERT(data_len > 0) ASSERT(data_len <= o->packet_len - o->pos) // update position o->pos += data_len; // if everything was received, notify user if (o->pos == o->packet_len) { DEBUGERROR(&o->d_err, o->handler(o->user)); return; } // receive more StreamRecvInterface_Receiver_Recv(o->input, o->packet + o->pos, o->packet_len - o->pos); }
/* * TransmitDisableMUX assembles a control disable mux packet and initializes the transmit procedure * * Params: * acktype specifies host or client as well as failure or success * mux is the MUX object the data is to be transmitted through */ int32 TransmitDisableMUX (int8 acktype, MUX* mux) { COMMBUFF* commbuff; DISABLEMUX_PACKET* packetdata; DEBUG("TransmitDisableMUX(%lu, %p)\n", (int32)acktype, mux); commbuff = int_alloc_commbuff(sizeof(DISABLEMUX_PACKET)); packetdata = (DISABLEMUX_PACKET*)commbuff_data(commbuff); packetdata->type = PACKETTYPE_DISABLEMUX; commbuff_copyin_byte(commbuff, offsetof(DISABLEMUX_PACKET, acktype), acktype); queue_commbuff(commbuff, &mux->send_queue); mux->total_queued_amount += sizeof(DISABLEMUX_PACKET); task_schedule(&mux->send_task); return DEBUGERROR(ERROR_NONE); }
static void init_control_io (BSocksClient *o); static void free_control_io (BSocksClient *o); static void init_up_io (BSocksClient *o); static void free_up_io (BSocksClient *o); static int reserve_buffer (BSocksClient *o, bsize_t size); static void start_receive (BSocksClient *o, uint8_t *dest, int total); static void do_receive (BSocksClient *o); static void connector_handler (BSocksClient* o, int is_error); static void connection_handler (BSocksClient* o, int event); static void recv_handler_done (BSocksClient *o, int data_len); static void send_handler_done (BSocksClient *o); static void auth_finished (BSocksClient *p); void report_error (BSocksClient *o, int error) { DEBUGERROR(&o->d_err, o->handler(o->user, error)) } void init_control_io (BSocksClient *o) { // init receiving BConnection_RecvAsync_Init(&o->con); o->control.recv_if = BConnection_RecvAsync_GetIf(&o->con); StreamRecvInterface_Receiver_Init(o->control.recv_if, (StreamRecvInterface_handler_done)recv_handler_done, o); // init sending BConnection_SendAsync_Init(&o->con); PacketStreamSender_Init(&o->control.send_sender, BConnection_SendAsync_GetIf(&o->con), INT_MAX, BReactor_PendingGroup(o->reactor)); o->control.send_if = PacketStreamSender_GetInput(&o->control.send_sender); PacketPassInterface_Sender_Init(o->control.send_if, (PacketPassInterface_handler_done)send_handler_done, o); }
#include <pwd.h> #include <errno.h> #include <sys/stat.h> #include <fcntl.h> #include <misc/offset.h> #include <misc/open_standard_streams.h> #include <base/BLog.h> #include "BProcess.h" #include <generated/blog_channel_BProcess.h> static void call_handler (BProcess *o, int normally, uint8_t normally_exit_status) { DEBUGERROR(&o->d_err, o->handler(o->user, normally, normally_exit_status)) } static BProcess * find_process (BProcessManager *o, pid_t pid) { LinkedList2Iterator it; LinkedList2Iterator_InitForward(&it, &o->processes); LinkedList2Node *node; while (node = LinkedList2Iterator_Next(&it)) { BProcess *p = UPPER_OBJECT(node, BProcess, list_node); if (p->pid == pid) { LinkedList2Iterator_Free(&it); return p; } }