/** Implements notification in order to track socket state. */
  @Override
  public synchronized void onSctpNotification(SctpSocket socket, SctpNotification notification) {
    if (logger.isDebugEnabled()) {
      logger.debug("socket=" + socket + "; notification=" + notification);
    }
    switch (notification.sn_type) {
      case SctpNotification.SCTP_ASSOC_CHANGE:
        SctpNotification.AssociationChange assocChange =
            (SctpNotification.AssociationChange) notification;

        switch (assocChange.state) {
          case SctpNotification.AssociationChange.SCTP_COMM_UP:
            if (!assocIsUp) {
              boolean wasReady = isReady();

              assocIsUp = true;
              if (isReady() && !wasReady) notifySctpConnectionReady();
            }
            break;

          case SctpNotification.AssociationChange.SCTP_COMM_LOST:
          case SctpNotification.AssociationChange.SCTP_SHUTDOWN_COMP:
          case SctpNotification.AssociationChange.SCTP_CANT_STR_ASSOC:
            try {
              closeStream();
            } catch (IOException e) {
              logger.error("Error closing SCTP socket", e);
            }
            break;
        }
        break;
    }
  }
  /**
   * Makes an <tt>RTCPREMBPacket</tt> that provides receiver feedback to the endpoint from which we
   * receive.
   *
   * @return an <tt>RTCPREMBPacket</tt> that provides receiver feedback to the endpoint from which
   *     we receive.
   */
  private RTCPREMBPacket makeRTCPREMBPacket() {
    // TODO we should only make REMBs if REMB support has been advertised.
    // Destination
    RemoteBitrateEstimator remoteBitrateEstimator =
        ((VideoMediaStream) getStream()).getRemoteBitrateEstimator();

    Collection<Integer> ssrcs = remoteBitrateEstimator.getSsrcs();

    // TODO(gp) intersect with SSRCs from signaled simulcast layers
    // NOTE(gp) The Google Congestion Control algorithm (sender side)
    // doesn't seem to care about the SSRCs in the dest field.
    long[] dest = new long[ssrcs.size()];
    int i = 0;

    for (Integer ssrc : ssrcs) dest[i++] = ssrc & 0xFFFFFFFFL;

    // Exp & mantissa
    long bitrate = remoteBitrateEstimator.getLatestEstimate();

    if (bitrate == -1) return null;

    if (logger.isDebugEnabled()) logger.debug("Estimated bitrate: " + bitrate);

    // Create and return the packet.
    // We use the stream's local source ID (SSRC) as the SSRC of packet
    // sender.
    long streamSSRC = getLocalSSRC();

    return new RTCPREMBPacket(streamSSRC, /* mediaSSRC */ 0L, bitrate, dest);
  }
示例#3
0
 private void handleResquest(String s) {
   Logger.info("@ClientMediator.handleResquest id=" + _id + " :s=" + s);
   if (s.indexOf("sync") > -1) {
     tellClient("sync " + s.split(" ")[1], 0);
   } else if (s.indexOf("get-status") > -1) {
     Integer[] ts = (Integer[]) tankStateProxy().getTanks();
     Logger.debug("ClientMediator.handleResquest: ts.len=" + ts.length);
     for (int i = 0; i < ts.length; i++) {
       ClientMediator cm =
           (ClientMediator) appFacade().retrieveMediator(Const.CLIENT_MEDIATOR + ts[i].intValue());
       TankState t = cm.getState();
       if (t == null || cm.destroyd) continue;
       tellClient(
           "create tank "
               + t.tankID
               + " "
               + t.tankName
               + " 0 0 "
               + t.life
               + " 500 "
               + t.x
               + " "
               + t.y
               + " "
               + cm.getTankAngle()
               + " "
               + cm.getGunAngle(),
           0);
     }
   } else if (s.indexOf("born") > -1) {
     if (_state == null) Arena.addReq(_id, s, null);
   } else if (s.indexOf("move-to") > -1) {
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("rotate-to") > -1) { // rotate gun
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("shoot") > -1) {
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("talk") > -1) {
     if (_state != null) s = "talk " + _state.tankName + " say: " + s.substring(5);
     this.sendNotification(Const.BROAD_CAST, s, null);
   }
 }
示例#4
0
  /**
   * Creates an instance of <tt>ShowPreviewDialog</tt>
   *
   * @param chatPanel The <tt>ChatConversationPanel</tt> that is associated with this dialog.
   */
  ShowPreviewDialog(final ChatConversationPanel chatPanel) {
    this.chatPanel = chatPanel;

    this.setTitle(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_DIALOG_TITLE"));
    okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK"));
    cancelButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.CANCEL"));

    JPanel mainPanel = new TransparentPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    // mainPanel.setPreferredSize(new Dimension(200, 150));
    this.getContentPane().add(mainPanel);

    JTextPane descriptionMsg = new JTextPane();
    descriptionMsg.setEditable(false);
    descriptionMsg.setOpaque(false);
    descriptionMsg.setText(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_WARNING_DESCRIPTION"));

    Icon warningIcon = null;
    try {
      warningIcon =
          new ImageIcon(
              ImageIO.read(
                  GuiActivator.getResources().getImageURL("service.gui.icons.WARNING_ICON")));
    } catch (IOException e) {
      logger.debug("failed to load the warning icon");
    }
    JLabel warningSign = new JLabel(warningIcon);

    JPanel warningPanel = new TransparentPanel();
    warningPanel.setLayout(new BoxLayout(warningPanel, BoxLayout.X_AXIS));
    warningPanel.add(warningSign);
    warningPanel.add(Box.createHorizontalStrut(10));
    warningPanel.add(descriptionMsg);

    enableReplacement =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
    enableReplacement.setOpaque(false);
    enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
    enableReplacementProposal =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"));
    enableReplacementProposal.setOpaque(false);

    JPanel checkBoxPanel = new TransparentPanel();
    checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS));
    checkBoxPanel.add(enableReplacement);
    checkBoxPanel.add(enableReplacementProposal);

    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);

    mainPanel.add(warningPanel);
    mainPanel.add(Box.createVerticalStrut(10));
    mainPanel.add(checkBoxPanel);
    mainPanel.add(buttonsPanel);

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    this.setPreferredSize(new Dimension(390, 230));
  }
  private void runOnDtlsTransport(StreamConnector connector) throws IOException {
    DtlsControlImpl dtlsControl = (DtlsControlImpl) getTransportManager().getDtlsControl(this);
    DtlsTransformEngine engine = dtlsControl.getTransformEngine();
    final DtlsPacketTransformer transformer = (DtlsPacketTransformer) engine.getRTPTransformer();

    byte[] receiveBuffer = new byte[SCTP_BUFFER_SIZE];

    if (LOG_SCTP_PACKETS) {
      System.setProperty(
          ConfigurationService.PNAME_SC_HOME_DIR_LOCATION, System.getProperty("java.io.tmpdir"));
      System.setProperty(
          ConfigurationService.PNAME_SC_HOME_DIR_NAME, SctpConnection.class.getName());
    }

    synchronized (this) {
      // FIXME local SCTP port is hardcoded in bridge offer SDP (Jitsi
      // Meet)
      sctpSocket = Sctp.createSocket(5000);
      assocIsUp = false;
      acceptedIncomingConnection = false;
    }

    // Implement output network link for SCTP stack on DTLS transport
    sctpSocket.setLink(
        new NetworkLink() {
          @Override
          public void onConnOut(SctpSocket s, byte[] packet) throws IOException {
            if (LOG_SCTP_PACKETS) {
              LibJitsi.getPacketLoggingService()
                  .logPacket(
                      PacketLoggingService.ProtocolName.ICE4J,
                      new byte[] {0, 0, 0, (byte) debugId},
                      5000,
                      new byte[] {0, 0, 0, (byte) (debugId + 1)},
                      remoteSctpPort,
                      PacketLoggingService.TransportName.UDP,
                      true,
                      packet);
            }

            // Send through DTLS transport
            transformer.sendApplicationData(packet, 0, packet.length);
          }
        });

    if (logger.isDebugEnabled()) {
      logger.debug("Connecting SCTP to port: " + remoteSctpPort + " to " + getEndpoint().getID());
    }

    sctpSocket.setNotificationListener(this);
    sctpSocket.listen();

    // FIXME manage threads
    threadPool.execute(
        new Runnable() {
          @Override
          public void run() {
            SctpSocket sctpSocket = null;
            try {
              // sctpSocket is set to null on close
              sctpSocket = SctpConnection.this.sctpSocket;
              while (sctpSocket != null) {
                if (sctpSocket.accept()) {
                  acceptedIncomingConnection = true;
                  break;
                }
                Thread.sleep(100);
                sctpSocket = SctpConnection.this.sctpSocket;
              }
              if (isReady()) {
                notifySctpConnectionReady();
              }
            } catch (Exception e) {
              logger.error("Error accepting SCTP connection", e);
            }

            if (sctpSocket == null && logger.isInfoEnabled()) {
              logger.info(
                  "SctpConnection " + getID() + " closed" + " before SctpSocket accept()-ed.");
            }
          }
        });

    // Notify that from now on SCTP connection is considered functional
    sctpSocket.setDataCallback(this);

    // Setup iceSocket
    DatagramSocket datagramSocket = connector.getDataSocket();
    if (datagramSocket != null) {
      this.iceSocket = new IceUdpSocketWrapper(datagramSocket);
    } else {
      this.iceSocket = new IceTcpSocketWrapper(connector.getDataTCPSocket());
    }

    DatagramPacket rcvPacket = new DatagramPacket(receiveBuffer, 0, receiveBuffer.length);

    // Receive loop, breaks when SCTP socket is closed
    try {
      do {
        iceSocket.receive(rcvPacket);

        RawPacket raw =
            new RawPacket(rcvPacket.getData(), rcvPacket.getOffset(), rcvPacket.getLength());

        raw = transformer.reverseTransform(raw);
        // Check for app data
        if (raw == null) continue;

        if (LOG_SCTP_PACKETS) {
          LibJitsi.getPacketLoggingService()
              .logPacket(
                  PacketLoggingService.ProtocolName.ICE4J,
                  new byte[] {0, 0, 0, (byte) (debugId + 1)},
                  remoteSctpPort,
                  new byte[] {0, 0, 0, (byte) debugId},
                  5000,
                  PacketLoggingService.TransportName.UDP,
                  false,
                  raw.getBuffer(),
                  raw.getOffset(),
                  raw.getLength());
        }

        // Pass network packet to SCTP stack
        sctpSocket.onConnIn(raw.getBuffer(), raw.getOffset(), raw.getLength());
      } while (true);
    } finally {
      // Eventually, close the socket although it should happen from
      // expire().
      synchronized (this) {
        assocIsUp = false;
        acceptedIncomingConnection = false;
        if (sctpSocket != null) {
          sctpSocket.close();
          sctpSocket = null;
        }
      }
    }
  }
  /**
   * Handles control packet.
   *
   * @param data raw packet data that arrived on control PPID.
   * @param sid SCTP stream id on which the data has arrived.
   */
  private synchronized void onCtrlPacket(byte[] data, int sid) throws IOException {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    int messageType = /* 1 byte unsigned integer */ 0xFF & buffer.get();

    if (messageType == MSG_CHANNEL_ACK) {
      if (logger.isDebugEnabled()) {
        logger.debug(getEndpoint().getID() + " ACK received SID: " + sid);
      }
      // Open channel ACK
      WebRtcDataStream channel = channels.get(sid);
      if (channel != null) {
        // Ack check prevents from firing multiple notifications
        // if we get more than one ACKs (by mistake/bug).
        if (!channel.isAcknowledged()) {
          channel.ackReceived();
          notifyChannelOpened(channel);
        } else {
          logger.warn("Redundant ACK received for SID: " + sid);
        }
      } else {
        logger.error("No channel exists on sid: " + sid);
      }
    } else if (messageType == MSG_OPEN_CHANNEL) {
      int channelType = /* 1 byte unsigned integer */ 0xFF & buffer.get();
      int priority = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      long reliability = /* 4 bytes unsigned integer */ 0xFFFFFFFFL & buffer.getInt();
      int labelLength = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      int protocolLength = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      String label;
      String protocol;

      if (labelLength == 0) {
        label = "";
      } else {
        byte[] labelBytes = new byte[labelLength];

        buffer.get(labelBytes);
        label = new String(labelBytes, "UTF-8");
      }
      if (protocolLength == 0) {
        protocol = "";
      } else {
        byte[] protocolBytes = new byte[protocolLength];

        buffer.get(protocolBytes);
        protocol = new String(protocolBytes, "UTF-8");
      }

      if (logger.isDebugEnabled()) {
        logger.debug(
            "!!! "
                + getEndpoint().getID()
                + " data channel open request on SID: "
                + sid
                + " type: "
                + channelType
                + " prio: "
                + priority
                + " reliab: "
                + reliability
                + " label: "
                + label
                + " proto: "
                + protocol);
      }

      if (channels.containsKey(sid)) {
        logger.error("Channel on sid: " + sid + " already exists");
      }

      WebRtcDataStream newChannel = new WebRtcDataStream(sctpSocket, sid, label, true);
      channels.put(sid, newChannel);

      sendOpenChannelAck(sid);

      notifyChannelOpened(newChannel);
    } else {
      logger.error("Unexpected ctrl msg type: " + messageType);
    }
  }
 private void logDebug(String msg) {
   if (logger.isDebugEnabled()) {
     msg = getSimulcastEngine().getVideoChannel().getEndpoint().getID() + ": " + msg;
     logger.debug(msg);
   }
 }
示例#8
0
 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
 private void sendInterruptMarker() {
   LOG.debug("Sending interrupt marker in order to interrupt feed consumer");
   changes.offer(INTERRUPT_MARKER);
 }
示例#9
0
 public void cancel() {
   LOG.debug("Feed cancelled");
   shouldRun = false;
   thread.interrupt();
 }
示例#10
0
 private void handleHeartbeat() {
   LOG.debug("Got heartbeat from DB");
 }
示例#11
0
  public void handleNotification(INotification notification) {
    //		Logger.debug("@ClientMediator.handleNotification:noti="+notification.getBody());
    String noname = notification.getName();
    if (noname == Const.TICK) {
      if (destroyd) return;
      long t = TimerCmd.timeStamp;

      String[] ary;
      int st, ed;
      if (_lastRotTank != null) {
        ary = _lastRotTank.split(" ");
        st = Integer.parseInt(ary[0]);
        ed = st + Integer.parseInt(ary[6]);
        if (t <= ed && t >= st) {
          int ist = Integer.parseInt(ary[0]);
          if (_move.size() > 0) {
            st = Integer.parseInt(_move.peek().split(" ")[0]);
            while (st < ist && _move.size() > 0) {
              _move.poll();
              if (_move.size() == 0) break;
              st = Integer.parseInt(_move.peek().split(" ")[0]);
            }
          }
        }
      }
      if (_move.size() > 0) {
        ary = _move.peek().split(" ");
        st = Integer.parseInt(ary[0]);
        ed = st + Integer.parseInt(ary[8]);

        while ((t > ed) && _move.size() > 0) {
          //					Logger.debug("@TankMediator.handleNotification: t = " + t + " st = " + st + "
          // ed="+ed);
          String p = (String) _move.poll();
          Logger.debug("ClientMediator.TICK _move.poll=" + p);
          if (_move.size() == 0) break;
          ary = _move.peek().split(" ");
          st = Integer.parseInt(ary[0]);
          ed = st + Integer.parseInt(ary[8]);
        }

        if (_move.size() > 0) {
          String[] li = (String[]) _move.toArray(new String[0]);
          for (int i = li.length - 1; i >= 0; i--) {
            String s = li[i];
            ary = s.split(" ");
            st = Integer.parseInt(ary[0]);
            ed = st + Integer.parseInt(ary[8]);
            if (t <= ed && t >= st) {
              if (t == st) { // ed==st in this situation
                _state.x = (int) Float.parseFloat(ary[4]);
                _state.y = (int) Float.parseFloat(ary[5]);
                _nextX = _state.x;
                _nextY = _state.y;
              } else {
                float sx = Float.parseFloat(ary[4]);
                float ex = Float.parseFloat(ary[6]);
                float sy = Float.parseFloat(ary[5]);
                float ey = Float.parseFloat(ary[7]);
                double eco = 1.0 * (t - st) / (ed - st);
                _state.x = (int) (sx + (ex - sx) * eco);
                _state.y = (int) (sy + (ey - sy) * eco);
                double neco = 1.0 * (t + 1 - st) / (ed - st);
                _nextX = (sx + (ex - sx) * neco);
                _nextY = (sy + (ey - sy) * neco);
              }
              while (_move.size() > 1) _move.poll();
              break;
            }
          }
        }
      }
      if (_state != null) {
        ConcurrentHashMap<Integer, BulletState> bs =
            ((ServerBulletMediator) (appFacade().retrieveMediator(Const.SERVER_BULLET_MEDIATOR)))
                .getBullets();
        for (Enumeration enu = bs.keys(); enu.hasMoreElements(); ) {
          int id = (Integer) enu.nextElement();
          BulletState blt = bs.get(id);
          if (Texter.distance(blt.x, blt.y, _state.x, _state.y) < 16) {
            this.sendNotification(Const.BROAD_CAST, "destroy bullet " + id, null);
            _state.life -= 100;
            if (_state.life <= 0) {
              this.sendNotification(Const.BROAD_CAST, "destroy tank " + _state.tankID, null);
            } else {
              this.sendNotification(
                  Const.BROAD_CAST, "set-life tank " + _state.tankID + " " + _state.life, null);
            }
          }
        }
      }

      // barrier and tank
      if (_state != null) {
        // colision detection
        //				Logger.only("ClientMediator.handleNotification: x="+_state.x+" y="+_state.y+"
        // nx="+_nextX+" ny="+_nextY+" "+Texter.sqrareDis(_nextX, _nextY, 470, 200)+"
        // "+Texter.sqrareDis(_state.x, _state.y, 470, 200));
        if (!Arena.canGo(_state.x, _state.y, _nextX, _nextY)) {
          Arena.addReq(_id, Const.STOP_MOVE, getState());
        }
        for (Enumeration enu = AcceptCmd.clients.elements(); enu.hasMoreElements(); ) {
          ClientMediator cmm = (ClientMediator) enu.nextElement();
          if (cmm.destroyd) return;
          int cmid = cmm.getID();
          if (cmid == _id) continue;
          TankState ts = cmm.getState();
          if (ts == null) continue;
          double curdis = Texter.distance(ts.x, ts.y, _state.x, _state.y);
          double netdis = Texter.distance(ts.x, ts.y, _nextX, _nextY);
          if (curdis < 40 && netdis < curdis) {
            Arena.addReq(_id, Const.STOP_MOVE, getState());
            Arena.addReq(cmid, Const.STOP_MOVE, ts);
          }
        }
      }

      // handle delayed first
      //			ary=_delayOrder.toArray(new String[0]);
      //			_delayOrder.clear();
      //			for(int i=0;i<ary.length;i++){
      //				Logger.only("delayArray: "+ary[i]);
      //				int ttt=Integer.parseInt(ary[i].split(" ")[0]);
      //				if(ttt==t){
      //					tellClientWithTime(ary[i]);
      //				}else if(ttt>t){
      //					_delayOrder.add(ary[i]);
      //				}
      //			}

    } else if (noname == Const.BROAD_CAST) {
      String s = (String) notification.getBody();
      String ary[] = s.split(" ");

      if (notification.getType() == Const.NO_PREFIX) {
        tellClientWithTime(s);
        return;
      } else if (s.indexOf("talk") > -1) {
        tellClient(s, 0);
        return;
      }
      if (_id == Integer.parseInt(ary[2])) {
        if (s.indexOf("rotate-gun") > -1) {
          _lastRotateGun = TimerCmd.timeStamp + " " + s;
          if (_state != null) _state.gunAngle = Float.parseFloat(_lastRotateGun.split(" ")[5]);
        } else if (s.indexOf("move tank") > -1) {
          Logger.debug("ClientMediator: move add s=" + s);
          int offset = Integer.parseInt(notification.getType());
          if (offset == 0) _move.clear();
          _move.add((TimerCmd.timeStamp + offset) + " " + s);
        } else if (s.indexOf("create tank") > -1) {
          _state =
              new TankState(
                  _id,
                  ary[3],
                  Integer.parseInt(ary[6]),
                  (int) Float.parseFloat(ary[8]),
                  (int) Float.parseFloat(ary[9]),
                  Float.parseFloat(ary[10]),
                  Float.parseFloat(ary[11]));
          _state.printState();
        } else if (s.indexOf("rotate-tank") > -1) {
          _lastRotTank = TimerCmd.timeStamp + " " + s;
          if (_state != null) _state.tankAngle = Float.parseFloat(_lastRotTank.split(" ")[5]);
        } else if (s.indexOf("destroy tank") > -1) {
          this.destroyd = true;
        }
      }
      if (notification.getType() != null) tellClient(s, Integer.parseInt(notification.getType()));
      else tellClient(s, 0);
    }
  }
示例#12
0
  /**
   * Enables or disables this <tt>RTPConnectorInputStream</tt>. While the stream is disabled, it
   * does not accept any packets.
   *
   * @param enabled <tt>true</tt> to enable, <tt>false</tt> to disable.
   */
  public void setEnabled(boolean enabled) {
    if (logger.isDebugEnabled()) logger.debug("setEnabled: " + enabled);

    this.enabled = enabled;
  }