Esempio n. 1
0
File: sfkmodel.py Progetto: qwdm/scp
 def _make_auth_packet(self):
     pb = scp_pb.Msg()
     pb.mtype = pb.AUTH
     pb.auth.token = self.token
     pb.auth.appid = self.appid
     protobuf = pb.SerializeToString()
     return prot.ScpPacket(protobuf=protobuf)
Esempio n. 2
0
 def make_sfkcontent(uri, request_id, headers=None):
     """ headers: list of strings like "Accept-Encoding: gzip,deflate,sdch"  """
     pb = scp_pb2.Msg()
     pb.mtype = pb.SFKCONTENT
     pb.content.identifier = uri
     pb.content.request_id = request_id
     for header in headers:
         pb.content.headers.append(header)
     return ScpPacket(protobuf=pb.SerializeToString())
Esempio n. 3
0
 def __init__(self, flags='\x00', guid='\x00' * 16, protobuf='', data=''):
     super(ScpPacket, self).__init__()
     self.flags = flags
     self.guid = guid
     if not protobuf:
         pb = scp_pb2.Msg()
         pb.mtype = pb.MESSAGE
         self.protobuf = pb.SerializeToString()
     else:
         self.protobuf = protobuf
     self.data = data
Esempio n. 4
0
 def get_auth_info(self):  # from sfk in very first packet
     """ extract appid, token from very first (auth) packet from sfk.
         return (None, None) if any errors happened
     """
     pb = scp_pb2.Msg()
     try:
         pb.ParseFromString(self.protobuf)
     except Exception as e:
         LOGGER.error(str(e))
         return None, None
     else:
         return pb.auth.appid, pb.auth.token
Esempio n. 5
0
 def get_sfkcontent(self):
     try:
         pb = scp_pb2.Msg()
         pb.ParseFromString(self.protobuf)
         if pb.mtype == pb.SFKCONTENT:
             uri = pb.content.identifier
             request_id = pb.content.request_id
             headers = []
             for header in pb.content.headers:
                 headers.append(header)
             return (uri, request_id, headers)
         else:
             raise FieldExtractionError(
                 "Not SfkContent packet, try to extract uri and headers")
     except Exception as e:
         raise FieldExtractionError("Can't extract SkfContent field", e)
Esempio n. 6
0
    def get_msg_type(self):
        pb = scp_pb2.Msg()
        try:
            pb.ParseFromString(self.protobuf)
        except Exception as e:
            LOGGER.error("Cannot parse protobuf")
            return None

        msg_type = {
            pb.AUTH: 'auth',
            pb.PING: 'ping',
            pb.MESSAGE: 'msg',
            pb.PONG: 'pong',
            pb.SFKCONTENT: 'sfkcontent',
            pb.SESSION_DROPPED: 'session_dropped',
        }.get(pb.mtype, None)
        #        if msg_type is None:
        #            raise ProtocolError("bad mtype")
        #        else:   # no one catch this exception!!!
        return msg_type
Esempio n. 7
0
 def make_session_dropped(guid):
     pb = scp_pb2.Msg()
     pb.mtype = pb.SESSION_DROPPED
     return ScpPacket(guid=guid, protobuf=pb.SerializeToString())
Esempio n. 8
0
 def make_pong(self):
     pb = scp_pb2.Msg()
     pb.mtype = pb.PONG
     pb.pong.ctime = 0
     pong = ScpPacket(guid=self.guid, protobuf=pb.SerializeToString())
     return pong
Esempio n. 9
0
File: sfkmodel.py Progetto: qwdm/scp
 def _make_ping_packet(self):
     pb = scp_pb.Msg()
     pb.mtype = pb.PING
     pb.ping.ctime = 0
     protobuf = pb.SerializeToString()
     return prot.ScpPacket(protobuf=protobuf)