Exemple #1
0
    def createchan(self, pkt, x, y):
        # Older clients first report version here
        self.version=pkt.p2

        name=str(pkt.body).strip('\0')
        pv = self.server.GetPV(name)

        if pv is None:
            # PV does not exist
            log.debug("Can't create channel for non-existant PV %s",name)
            fail = CAmessage(cmd=26, p1=pkt.p1)
            self.send(fail.pack())
            return

        chan=Channel(self.next_sid, pkt.p1, self.server, self, pv)
        self.channels[chan.sid]=chan
        dtype, maxcount = pv.info(chan)

        ok = CAmessage(cmd=18, dtype=dtype, count=maxcount,
                       p1=pkt.p1, p2=chan.sid)

        rights = CAmessage(cmd=22, p1=pkt.p1, p2=chan.rights)

        self.send(ok.pack()+rights.pack())
        
        self.next_sid=self.next_sid+1
        while self.next_sid in self.channels:
            self.next_sid=self.next_sid+1
Exemple #2
0
 def clearchan(self, pkt, x, y):
     chan=self.channels.get(pkt.p1)
     if not chan:
         log.warning('Attempt to clean non-existent channel')
         return
     
     chan.close()
     ok = CAmessage(cmd=12, p1=pkt.p1, p2=pkt.p2)
     self.send(ok.pack())
Exemple #3
0
    def monitordel(self, pkt, peer, circuit):
        if pkt.p2 not in self.monitors:
            raise CAError('Attempt to cancel non-existant monitor',
                          ECA_BADCHID)

        mon = self.monitors.pop(pkt.p2)
        log.debug('Del %s', mon)

        pkt = CAmessage(cmd=1, dtype=mon.dbr, p1=self.circuit.cid, p2=mon.ioid)
        self.circuit.send(pkt.pack())
Exemple #4
0
    def regreq(self, peer):
        node = RepeaterNode(self, peer)
        p = Port(0, node, 'localhost')
        p.startListening()
        p.connect(peer[0], peer[1])

        self.clients.add(node)
        log.debug('Repeater add %s', peer)

        rep = CAmessage(cmd=17, p2=INADDR_LOOPBACK)

        node.transport.write(rep.pack())
Exemple #5
0
    def connectionMade(self):
        self.peer=self.transport.getPeer()
        self.tcpport=self.transport.getHost().port

        # before 3.14.12 servers didn't send version until client authenticated
        # from 3.14.12 clients attempting to do TCP name resolution don't authenticate
        # but expect a version message immediately
        pkt=CAmessage(cmd=0, dtype=self.prio, count=defs.CA_VERSION)
        self.send(pkt.pack())
        log.debug('connection from %s',self.peer)
        log.debug('Create %s',self)

        self.server.circuits.add(self)

        self.__D=DeferredManager()
        self.__C.callback(self)
Exemple #6
0
    def close(self, connected=False):
        """Called when the client closes the channel
        """
        log.debug('Destroy %s', self)
        self.pv.disconnect(self)

        if self.__D is not None:
            self.__D.addErrback(lambda e: e.trap(CancelledError))
            self.__D.cancel()
            self.__D = None

        if connected:
            pkt = CAmessage(cmd=27, p1=self.cid)
            self.circuit.send(pkt.pack())

        self.circuit.dropchan(self)
Exemple #7
0
    def nameres(self, pkt, endpoint, peer):
        name=str(pkt.body).strip('\0')
        log.info('%s is looking for %s',str(peer),name)
        ret = self.Lookup(name)
        if isinstance(ret, tuple) and pkt.count<11:
            # redirect not supported by older clients
            return

        elif ret and not isinstance(ret, tuple):
            ret = (0xffffffff, endpoint.tcpport)

        if ret:
            ack=CAmessage(cmd=6, size=8, dtype=ret[1],
                          p1=ret[0], p2=pkt.p2,
                          body=packSearchBody(CA_VERSION))

            endpoint.sendto(ack.pack(), peer)