Ejemplo n.º 1
0
def regclc():
    clc_ip = lyconf.Config.clc_ip
    clc_port = lyconf.Config.clc_port
    tag = lyconf.Config.tag
    mykey = lyconf.Config.key
    myuuid = lyutil.myuuid()
    if myuuid == 1:
        LOG.error("failed generating uuid")
        return None
    LOG.info("osm challenge myuuid: %s" % myuuid)
    for i in range(len(myuuid), lydef.LUOYUN_AUTH_DATA_LEN):
        myuuid += '\x00'

    data = []
    for m in myuuid:
        data.append(ord(m))
    challenge = lyauth.encode(mykey, data)
    challengestr = b''
    for m in challenge:
        challengestr += chr(m)

    LOG.info("connecting %s:%d" % (clc_ip, clc_port))
    sock = None
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.connect((clc_ip, clc_port))
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
        sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE,
                        LY_OSM_KEEPALIVE_INTVL)
        sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL,
                        LY_OSM_KEEPALIVE_INTVL)
        sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
                        LY_OSM_KEEPALIVE_PROBES)
        sock.setblocking(0)
    except socket.error, (value, message):
        LOG.warn(message)
        if sock:
            sock.close()
        return None
Ejemplo n.º 2
0
def regclc():
  clc_ip = lyconf.Config.clc_ip
  clc_port = lyconf.Config.clc_port
  tag = lyconf.Config.tag
  mykey = lyconf.Config.key
  myuuid = lyutil.myuuid()
  if myuuid == 1:
    LOG.error("failed generating uuid")
    return None
  LOG.info("osm challenge myuuid: %s" % myuuid)
  for i in range(len(myuuid), lydef.LUOYUN_AUTH_DATA_LEN):
    myuuid += '\x00'

  data = []
  for m in myuuid:
    data.append(ord(m))
  challenge = lyauth.encode(mykey, data)
  challengestr = b''
  for m in challenge:
    challengestr += chr(m)

  LOG.info("connecting %s:%d" % (clc_ip, clc_port))
  sock = None
  try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.connect((clc_ip, clc_port))
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, LY_OSM_KEEPALIVE_INTVL)
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, LY_OSM_KEEPALIVE_INTVL)
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, LY_OSM_KEEPALIVE_PROBES)
    sock.setblocking(0)
  except socket.error, (value,message): 
    LOG.warn(message)
    if sock: 
        sock.close()
    return None 
Ejemplo n.º 3
0
            LOG.error("error in sockrecv")
            return None
        if result == 0:
            LOG.error("socket closed")
            return None
        t, l, rettag, challenge = struct.unpack(
            "=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
        if t != lydef.PKT_TYPE_OSM_AUTH_REQUEST:
            LOG.error("wrong packet %d" % t)
            return None
        LOG.info("auth request: %s" % challenge)

        data = []
        for m in challenge:
            data.append(ord(m))
        answer = lyauth.encode(mykey, data)
        answerstr = b''
        for m in answer:
            answerstr += chr(m)
        data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag, answerstr)
        lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REPLY, data)

        LOG.info("register to clc")
        regstr = str(tag) + ' ' + str(
            lydef.OSM_STATUS_UNREGISTERED) + ' ' + lyconf.Config.local_ip
        lyutil.socksend(sock, lydef.PKT_TYPE_OSM_REGISTER_REQUEST, regstr)

        LOG.info("waiting for clc reply")
        result, response = lyutil.sockrecv(sock)
        if result == -1:
            LOG.error("error in sockrecv")
Ejemplo n.º 4
0
    if result == -1 or len(response) != recvsize:
      LOG.error("error in sockrecv")
      return None
    if result == 0:
      LOG.error("socket closed")
      return None
    t, l, rettag, challenge = struct.unpack("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
    if t != lydef.PKT_TYPE_OSM_AUTH_REQUEST:
      LOG.error("wrong packet %d" % t)
      return None
    LOG.info("auth request: %s" % challenge)

    data = []
    for m in challenge:
      data.append(ord(m))
    answer = lyauth.encode(mykey, data)
    answerstr = b''
    for m in answer:
      answerstr += chr(m)
    data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag, answerstr)
    lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REPLY, data)

    LOG.info("register to clc")
    regstr = str(tag) + ' ' + str(lydef.OSM_STATUS_UNREGISTERED) + ' ' + lyconf.Config.local_ip
    lyutil.socksend(sock, lydef.PKT_TYPE_OSM_REGISTER_REQUEST, regstr)

    LOG.info("waiting for clc reply")
    result, response = lyutil.sockrecv(sock)
    if result == -1:
      LOG.error("error in sockrecv")
      return None