예제 #1
0
 def dbg_dialect(self, client=None):
     msg = "[sync]{\"type\":\"dialect\",\"dialect\":\"%s\"}\n" % self.current_dialect
     if client:
         client.client_sock.sendall(rs_encode(msg))
     else:
         for idbc in self.idb_clients:
             idbc.client_sock.sendall(rs_encode(msg))
예제 #2
0
    def switch_idb(self, new_idb):
        msg = "[sync]{\"type\":\"broker\",\"subtype\":\"%s\"}\n"
        if (not self.current_idb == new_idb) and (self.current_idb and self.current_idb.enabled):
            switchmsg = msg % 'disable_idb'
            self.current_idb.client_sock.sendall(rs_encode(switchmsg))
            self.current_idb.enabled = False

        if new_idb:
            switchmsg = msg % 'enable_idb'
            new_idb.client_sock.sendall(rs_encode(switchmsg))
            self.current_idb = new_idb
            self.current_idb.enabled = True
예제 #3
0
    def notice_dispatcher(self, type, args=None):
        if args:
            notice = "[notice]{\"type\":\"%s\",%s}\n" % (type, args)
        else:
            notice = "[notice]{\"type\":\"%s\"}\n" % (type)

        self.notify_socket.sendall(rs_encode(notice))
예제 #4
0
    def req_idb_n(self, s, hash):
        idb = hash['idb']
        try:
            idbn = int(idb)
        except (TypeError, ValueError) as e:
            s.sendall(rs_encode('> idb_n error: n should be a decimal value'))
            return

        try:
            idbc = self.idb_clients[idbn]
        except IndexError:
            msg = "> idb_n error: index %d is invalid (see idblist)" % idbn
            s.sendall(rs_encode(msg))
            return

        self.switch_idb(idbc)
        msg = "> active idb is now \"%s\" (%d)" % (idbc.name, idbn)
        s.sendall(rs_encode(msg))
예제 #5
0
    def req_idb_list(self, s, hash):
        clist = "> currently connected idb(s):\n"
        if not self.idb_clients:
            clist += "    no idb client yet\n"
        else:
            for i in range(len(self.idb_clients)):
                clist += ("    [%d] %s\n" % (i, self.idb_clients[i].name))

        s.sendall(rs_encode(clist))
예제 #6
0
    def forward(self, msg, s=None):
        if not s:
            if not self.current_idb:
                return
            s = self.current_idb.client_sock

        if s and self.current_idb.enabled:
            fwmsg = "%s\n" % msg
            s.sendall(rs_encode(fwmsg))
예제 #7
0
    def req_idb_n(self, s, hash):
        idb = hash['idb']
        try:
            idbn = int(idb)
        except (TypeError, ValueError):
            s.sendall("> n should be a decimal rs_encode(value)")
            return

        try:
            idbc = self.idb_clients[idbn]
        except IndexError:
            msg = "> %d is invalid (see idblist)" % idbn
            s.sendall(rs_encode(msg))
            return

        self.switch_idb(idbc)
        msg = "> current idb set to %d" % idbn
        s.sendall(rs_encode(msg))
예제 #8
0
    def announcement(self, msg, s=None):
        if not s:
            if not self.current_idb:
                return
            s = self.current_idb.client_sock

        try:
            announce = "[notice]{\"type\":\"dispatcher\",\"subtype\":\"msg\",\"msg\":\"%s\"}\n" % msg
            s.sendall(rs_encode(announce))
        except socket.error:
            return
예제 #9
0
 def req_cmd(self, s, hash):
     cmd = "%s\n" % hash['cmd']
     self.current_dbg.client_sock.sendall(rs_encode(cmd))
예제 #10
0
 def send_beacon(self, s):
     s.sendall(rs_encode("[notice]{\"type\":\"dispatcher\",\"subtype\":\"beacon\"}\n"))
예제 #11
0
 def puts(self, msg):
     sys.stdout.buffer.write(rs_encode(msg + '\n'))
     sys.stdout.flush()