Exemplo n.º 1
0
 @Override
 public D_ReleaseQuality decode(Decoder dec) throws ASN1DecoderFail {
   Decoder d = dec.getContent();
   _quality = d.getFirstObject(true).getSequenceOf(Encoder.TAG_UTF8String);
   description = d.getFirstObject(true).getString();
   return this;
 }
Exemplo n.º 2
0
 public static D_ReleaseQuality[] reconstructArrayFromString(String s) throws ASN1DecoderFail {
   if (s == null) return null;
   byte[] data = util.Base64Coder.decode(s);
   Decoder dec = new Decoder(data);
   D_ReleaseQuality result[] =
       dec.getSequenceOf(getASNType(), new D_ReleaseQuality[0], new D_ReleaseQuality());
   return result;
 }
Exemplo n.º 3
0
 public Address decode_V0(Decoder content) {
   address = content.getFirstObject(true).getString();
   setAddress(address);
   pure_protocol = content.getFirstObject(true).getString();
   Decoder d = content.getFirstObject(true);
   if (d != null) {
     certified = true;
     priority = d.getInteger().intValue();
   }
   return this;
 }
Exemplo n.º 4
0
 public Address decode(Decoder dec) {
   Decoder content;
   try {
     content = dec.getContent();
   } catch (ASN1DecoderFail e) {
     e.printStackTrace();
     return this;
   }
   if (content.getTypeByte() != DD.TAG_AC0) {
     if (content.getTypeByte() == Encoder.TAG_UTF8String) version_structure = V0;
     else if (content.getTypeByte() == Encoder.TAG_PrintableString) version_structure = V1;
     else {
       Util.printCallPath("Type=" + content.getTypeByte());
       throw new RuntimeException("Unknow Address version");
     }
   } else {
     if (DEBUG) System.out.println("Address:decode tag=" + content.getTypeByte());
     version_structure = content.getFirstObject(true).getInteger().intValue();
   }
   switch (version_structure) {
     case V0:
       if (DEBUG) System.out.println("Address:dec:V0");
       return decode_V0(content);
     case V1:
       if (DEBUG) System.out.println("Address:dec:V1");
       return decode_V1(content);
     case V2:
     case V3:
       if (DEBUG) System.out.println("Address:dec:V2");
       return decode_V2(content);
     default:
       Util.printCallPath("Type not yet supported=" + version_structure);
       throw new RuntimeException("Unknow Address version:" + version_structure);
   }
 }
Exemplo n.º 5
0
 public Address decode_V2(Decoder content) {
   // this.version_structure = V2;
   domain = content.getFirstObject(true).getString();
   tcp_port = content.getFirstObject(true).getInteger().intValue();
   udp_port = content.getFirstObject(true).getInteger().intValue();
   if (content.getTypeByte() == DD.TAG_AC1)
     pure_protocol = content.getFirstObject(true).getString();
   else pure_protocol = null;
   if (content.getTypeByte() == DD.TAG_AC2) branch = content.getFirstObject(true).getString();
   else branch = null;
   if (content.getTypeByte() == DD.TAG_AC3)
     agent_version = content.getFirstObject(true).getString();
   else agent_version = null;
   if (content.getTypeByte() == DD.TAG_AC4) {
     priority = content.getFirstObject(true).getInteger().intValue();
     certified = true;
   } else certified = false;
   return this;
 }
Exemplo n.º 6
0
 @Override
 public DirectoryAnswerInstance decode(Decoder dec) throws ASN1DecoderFail {
   Decoder d = dec.getContent();
   instance = d.getFirstObject(true).getString();
   branch = d.getFirstObject(true).getString();
   agent_version = d.getFirstObject(true).getIntsArray();
   date_last_contact = d.getFirstObject(true).getGeneralizedTimeCalenderAnyType();
   instance_terms =
       d.getFirstObject(true)
           .getSequenceOf(
               DIR_Terms_Requested.getASN1Type(),
               new DIR_Terms_Requested[0],
               new DIR_Terms_Requested());
   addresses = d.getFirstObject(true).getSequenceOfAL(Address.getASN1Type(), new Address());
   signature_peer = d.getFirstObject(true).getBytes();
   return this;
 }
Exemplo n.º 7
0
 public Address decode_V1(Decoder content) {
   // this._version_structure = V1;
   domain = content.getFirstObject(true).getString();
   tcp_port = content.getFirstObject(true).getInteger().intValue();
   Decoder udp_dec = content.getFirstObject(true);
   if (udp_dec != null) udp_port = udp_dec.getInteger().intValue();
   else {
     Util.printCallPath("Null decoder udp for " + this);
     udp_port = tcp_port;
   }
   if (content.getFirstObject(false) != null)
     pure_protocol = content.getFirstObject(true).getString();
   branch = null;
   this.agent_version = null;
   return this;
 }
Exemplo n.º 8
0
  public void __run(Socket client) {

    try {
      client.setSoTimeout(DirectoryServer.SOCKET_READ_TIMEOUT);
      // out.println("DirServ: Accepted... from: "+client.getRemoteSocketAddress());
      InetSocketAddress risa = null;
      try {
        // InetAddress risa = ((InetSocketAddress) client.getRemoteSocketAddress()).getAddress();
        risa = (InetSocketAddress) client.getRemoteSocketAddress();
      } catch (Exception e) {
        e.printStackTrace();
      }
      byte buffer[] = new byte[DirectoryServer.MAX_DR];
      int peek = client.getInputStream().read(buffer);
      if (peek < 0) {
        out.println("DirServTCP: got no bytes from: " + risa);
        return;
      } else {
        out.println("DirServTCP: __run got bytes from: " + risa);
      }
      // out.println("DirServ: Got ASN1 dump: "+Util.byteToHexDump(buffer,peek));
      Decoder test = new Decoder(buffer, 0, peek);
      // out.println("DirServTCP: __run got decoder: "+test);

      out.println(
          "DirServTCP: __run: Decoded ASN1: class="
              + test.typeClass()
              + " val="
              + test.tagVal()
              + " blen="
              + buffer.length);
      DirMessage m; // recording msgs
      if (test.typeClass() == Encoder.CLASS_APPLICATION
          && test.tagVal() == DirectoryAnnouncement.TAG) {
        // out.println("DirServ: Detected directory announcement");
        InetSocketAddress isa = (InetSocketAddress) client.getRemoteSocketAddress();
        DirectoryAnnouncement da = new DirectoryAnnouncement(buffer, peek, client.getInputStream());
        out.println("DirServTCP: got announcement: " + da + "\n from: " + isa);

        // here should first get the old detected address (probably from UDP) and keep it if has
        // same IP

        // this stores the message in the announcement_storage for this GID, and the GID - IP
        // relation in its hashtable
        DirectoryServer.recordAnnouncementMessage(
            isa, da, null, DirMessage.TCP, DirMessage.ANNOUNCEMENT);

        // creates an address object from the socket and reported udp port
        Address detected_sa = DirectoryServer.detectUDP_Address(isa, da.address.udp_port);
        out.println("DirServTCP: got announcement: detected = " + detected_sa);

        // Address detected_sa = new Address(_detected_sa);
        detected_sa = DirectoryServer.addr_NAT_detection(da, detected_sa);

        out.println("DirServTCP: got announcement: detected tuned = " + detected_sa);
        if (da.address.udp_port <= 0) detected_sa = null;

        boolean storeNAT;
        boolean TCP;
        DirectoryAnnouncement_Answer daa =
            DirectoryServer.handleAnnouncement(
                da, detected_sa, DirectoryServer.db_dir, storeNAT = false, TCP = true);
        byte[] answer = new byte[0];
        if (daa != null) answer = daa.encode();
        // byte[] answer = new D_DAAnswer(detected_sa).encode();
        client.getOutputStream().write(answer);

        DirectoryServer.recordAnnouncementMessage(
            isa, da, daa, DirMessage.TCP, DirMessage.ANN_ANSWER);
      } else {
        // boolean DEBUG = true;
        if (DEBUG) out.println("DSTCP: Potential directory request");
        // handling terms here
        DirectoryRequest dr = new DirectoryRequest(buffer, peek, client.getInputStream());
        if (dr.empty()) {
          out.println("DirServTCP:__run: potential message detected empty = " + risa + " dr=" + dr);
          return;
        }
        // boolean acceptedTerms = areTermsAccepted(dr);
        InetSocketAddress isa = (InetSocketAddress) client.getRemoteSocketAddress();
        if (DEBUG) out.println("Received directory request: " + dr);

        DirectoryServer.recordRequestMessage(isa, dr, null, DirMessage.TCP, DirMessage.REQUEST);
        if (DEBUG)
          out.println(
              "DirServ: Looking for: "
                  + D_Peer.getGIDHashFromGID(dr.globalID)
                  + "\n  by "
                  + D_Peer.getGIDHashFromGID(
                      dr.initiator_globalID)); // +"\n  with source udp="+dr.UDP_port);

        String globalID = dr.globalID; // looking for peer GID
        String globalIDhash = dr.globalIDhash; // looking for peer GID hash
        // de has the look-for-peer and all instances stored in the db
        D_DirectoryEntry de = DirectoryServerCache.getEntry(globalID, globalIDhash);
        if (DEBUG) out.println("DirServ: From cache got: " + de);
        ASNObj da = DirectoryServer.getDA(de, dr, dr.version);

        if ((da == null)) // || (da.date == null))
        {
          System.out.println(
              "DirectoryServer:__run: abandon: ?why da=" + da + "\n\tde=" + de + "\n\tdr=" + dr);
          return;
        }
        DirectoryServer.recordRequestMessage(
            isa, dr, da, DirMessage.TCP, DirMessage.REQUEST_ANSWER);

        byte msg[] = da.encode();
        if (DEBUG) {
          Decoder dec = new Decoder(msg);
          DirectoryAnswerMultipleIdentities dami = new DirectoryAnswerMultipleIdentities(dec);
          System.out.println("DirectoryServer:_run:encode " + da + "\nto " + dami);
        }
        // out.println("answer: "+Util.byteToHexDump(msg, " ")+"\n\tI.e.: "+da);
        /*
        if(_DEBUG&&(da.addresses.size()>0)){
        	out.println("DirServ: *******");
        	out.println("DirServ: Aanswer: "+client.getRemoteSocketAddress()+" <- "+da.toString());
        }
        */
        client.getOutputStream().write(msg);
      }
      client.close();
    } catch (SocketException e) {
      out.println("server: " + e);
      return;
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }