コード例 #1
0
  /** Handles the events CompleteComponentRegistrationNotification */
  public void handleCompleteComponentRegistrationNotificationEvent(
      final PlatformComponentProfile platformComponentProfileRegistered) {

    /*
     * If the component registered have my profile and my identity public key
     */
    if (platformComponentProfileRegistered.getPlatformComponentType()
            == PlatformComponentType.NETWORK_SERVICE
        && platformComponentProfileRegistered.getNetworkServiceType()
            == NetworkServiceType.CRYPTO_PAYMENT_REQUEST
        && platformComponentProfileRegistered
            .getIdentityPublicKey()
            .equals(identity.getPublicKey())) {

      /*
       * Mark as register
       */
      this.register = Boolean.TRUE;

      try {

        cryptoPaymentRequestExecutorAgent =
            new CryptoPaymentRequestExecutorAgent(
                this,
                errorManager,
                eventManager,
                cryptoPaymentRequestNetworkServiceDao,
                wsCommunicationsCloudClientManager,
                getPluginVersionReference());

        cryptoPaymentRequestExecutorAgent.start();

      } catch (CantStartAgentException e) {

        CantStartPluginException pluginStartException =
            new CantStartPluginException(e, "", "Problem initializing crypto payment request dao.");
        errorManager.reportUnexpectedPluginException(
            this.getPluginVersionReference(),
            UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
            pluginStartException);
      }
    }
  }
コード例 #2
0
  /**
   * (non-javadoc)
   *
   * @see CommunicationsClientConnection#requestVpnConnection(PlatformComponentProfile,
   *     PlatformComponentProfile)
   */
  @Override
  public void requestVpnConnection(
      PlatformComponentProfile applicant, PlatformComponentProfile remoteDestination)
      throws CantEstablishConnectionException {

    try {

      System.out.println("WsCommunicationsCloudClientConnection - requestVpnConnection");

      /*
       * Validate parameter
       */
      if (applicant == null || remoteDestination == null) {

        throw new IllegalArgumentException("All parameters are required, can not be null");
      }

      List<PlatformComponentProfile> participants = new ArrayList();
      participants.add(applicant);
      participants.add(remoteDestination);

      /** Validate all are the same type and NETWORK_SERVICE */
      for (PlatformComponentProfile participant : participants) {

        if (participant.getPlatformComponentType() != PlatformComponentType.NETWORK_SERVICE) {
          throw new IllegalArgumentException(
              "All the PlatformComponentProfile has to be NETWORK_SERVICE ");
        }

        if (participant.getNetworkServiceType() != applicant.getNetworkServiceType()) {
          throw new IllegalArgumentException(
              "All the PlatformComponentProfile has to be the same type of network service type ");
        }
      }

      /*
       * Construct the json object
       */
      Gson gson = new Gson();

      /*
       * Convert to json representation
       */
      String jsonListRepresentation =
          gson.toJson(
              participants,
              new TypeToken<List<PlatformComponentProfileCommunication>>() {}.getType());

      /*
       * Construct a fermat packet whit the request
       */
      FermatPacket fermatPacketRespond =
          FermatPacketCommunicationFactory.constructFermatPacketEncryptedAndSinged(
              wsCommunicationsCloudClientChannel.getServerIdentity(), // Destination
              wsCommunicationsCloudClientChannel.getClientIdentity().getPublicKey(), // Sender
              jsonListRepresentation, // Message Content
              FermatPacketType.COMPONENT_CONNECTION_REQUEST, // Packet type
              wsCommunicationsCloudClientChannel
                  .getClientIdentity()
                  .getPrivateKey()); // Sender private key
      /*
       * Send the encode packet to the server
       */
      wsCommunicationsCloudClientChannel.send(FermatPacketEncoder.encode(fermatPacketRespond));

    } catch (Exception e) {

      CantEstablishConnectionException pluginStartException =
          new CantEstablishConnectionException(
              CantEstablishConnectionException.DEFAULT_MESSAGE,
              e,
              e.getLocalizedMessage(),
              e.getLocalizedMessage());
      throw pluginStartException;
    }
  }
コード例 #3
0
  /**
   * (non-javadoc)
   *
   * @see CommunicationsClientConnection#requestDiscoveryVpnConnection(PlatformComponentProfile,
   *     PlatformComponentProfile, PlatformComponentProfile)
   */
  @Override
  public void requestDiscoveryVpnConnection(
      PlatformComponentProfile applicantParticipant,
      PlatformComponentProfile applicantNetworkService,
      PlatformComponentProfile remoteParticipant)
      throws CantEstablishConnectionException {

    try {

      System.out.println("WsCommunicationsCloudClientConnection - requestDiscoveryVpnConnection");

      /*
       * Validate parameter
       */
      if (applicantParticipant == null
          || applicantNetworkService == null
          || remoteParticipant == null) {

        throw new IllegalArgumentException("All parameters are required, can not be null");
      }

      /*
       * Validate are the  type NETWORK_SERVICE
       */
      if (applicantNetworkService.getPlatformComponentType()
          != PlatformComponentType.NETWORK_SERVICE) {
        throw new IllegalArgumentException(
            "All the PlatformComponentProfile has to be NETWORK_SERVICE ");
      }

      /*
       * Construct the json object
       */
      Gson gson = new Gson();
      JsonObject packetContent = new JsonObject();
      packetContent.addProperty(
          JsonAttNamesConstants.APPLICANT_PARTICIPANT_VPN, applicantParticipant.toJson());
      packetContent.addProperty(
          JsonAttNamesConstants.APPLICANT_PARTICIPANT_NS_VPN, applicantNetworkService.toJson());
      packetContent.addProperty(
          JsonAttNamesConstants.REMOTE_PARTICIPANT_VPN, remoteParticipant.toJson());

      /*
       * Convert to json representation
       */
      String packetContentJson = gson.toJson(packetContent);

      /*
       * Construct a fermat packet whit the request
       */
      FermatPacket fermatPacketRespond =
          FermatPacketCommunicationFactory.constructFermatPacketEncryptedAndSinged(
              wsCommunicationsCloudClientChannel.getServerIdentity(), // Destination
              wsCommunicationsCloudClientChannel.getClientIdentity().getPublicKey(), // Sender
              packetContentJson, // Message Content
              FermatPacketType.DISCOVERY_COMPONENT_CONNECTION_REQUEST, // Packet type
              wsCommunicationsCloudClientChannel
                  .getClientIdentity()
                  .getPrivateKey()); // Sender private key
      /*
       * Send the encode packet to the server
       */
      wsCommunicationsCloudClientChannel.send(FermatPacketEncoder.encode(fermatPacketRespond));

    } catch (Exception e) {

      CantEstablishConnectionException pluginStartException =
          new CantEstablishConnectionException(
              CantEstablishConnectionException.DEFAULT_MESSAGE,
              e,
              e.getLocalizedMessage(),
              e.getLocalizedMessage());
      throw pluginStartException;
    }
  }
コード例 #4
0
  /** Method tha send a new Message */
  public void sendNewMessage(
      PlatformComponentProfile sender, PlatformComponentProfile destination, String messageContent)
      throws CantSendMessageException {

    try {

      /*
       * ask for a previous connection
       */
      CommunicationNetworkServiceLocal communicationNetworkServiceLocal =
          communicationNetworkServiceConnectionManager.getNetworkServiceLocalInstance(
              destination.getIdentityPublicKey());

      if (communicationNetworkServiceLocal != null) {
        System.out.println(
            "*** 12345 case 7:send msg in NS P2P layer active connection"
                + new Timestamp(System.currentTimeMillis()));
        // Send the message
        communicationNetworkServiceLocal.sendMessage(
            sender.getIdentityPublicKey(),
            sender.getPlatformComponentType(),
            sender.getNetworkServiceType(),
            messageContent);

      } else {
        System.out.println(
            "*** 12345 case 6:send msg in NS P2P layer not active connection"
                + new Timestamp(System.currentTimeMillis()));
        /*
         * Created the message
         */
        FermatMessage fermatMessage =
            FermatMessageCommunicationFactory.constructFermatMessage(
                sender.getIdentityPublicKey(), // Sender
                sender.getPlatformComponentType(), // Sender Type
                sender.getNetworkServiceType(), // Sender NS Type
                destination.getIdentityPublicKey(), // Receiver
                destination.getPlatformComponentType(), // Receiver Type
                destination.getNetworkServiceType(), // Receiver NS Type
                messageContent, // Message Content
                FermatMessageContentType.TEXT // Type
                );

        /*
         * Configure the correct status
         */
        ((FermatMessageCommunication) fermatMessage)
            .setFermatMessagesStatus(FermatMessagesStatus.PENDING_TO_SEND);

        /*
         * Save to the data base table
         */
        communicationNetworkServiceConnectionManager.getOutgoingMessageDao().create(fermatMessage);

        /*
         * Ask the client to connect
         */
        communicationNetworkServiceConnectionManager.connectTo(
            sender, getNetworkServiceProfile(), destination);
      }

    } catch (Exception e) {

      System.out.println("Error sending message: " + e.getMessage());
      throw new CantSendMessageException(CantSendMessageException.DEFAULT_MESSAGE, e);
    }
  }