Protocol.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package de.tudarmstadt.informatik.hostage.protocol;
  2. import java.util.List;
  3. import de.tudarmstadt.informatik.hostage.wrapper.Packet;
  4. /**
  5. * Interface for protocols that are used by the application.
  6. * @param <T> Denotes if the protocol is using Strings or ByteArrays.
  7. * @author Mihai Plasoianu
  8. * @author Wulf Pfeiffer
  9. */
  10. public interface Protocol {
  11. /**
  12. * Represents who starts the communication once the connection is established.
  13. */
  14. public static enum TALK_FIRST {
  15. SERVER, CLIENT
  16. };
  17. /**
  18. * Returns the port on which the protocol is running.
  19. * @return the port used by the protocol (range: 0-65535)
  20. */
  21. int getPort();
  22. /**
  23. * Returns who starts the communication (server or client)
  24. * @return TALK_FIRST.server if the server starts or TALK_FIRST.client if the client starts.
  25. */
  26. TALK_FIRST whoTalksFirst();
  27. /**
  28. * Determines the next message that is sent by the server.
  29. * @param message last message that was sent by the client.
  30. * @return next message that will be sent.
  31. */
  32. List<Packet> processMessage(Packet packet);
  33. /**
  34. * Returns whether the communication is ended and the connection should be closed or not.
  35. * @return true if the connection should be closed, else false.
  36. */
  37. boolean isClosed();
  38. /**
  39. * Returns if the protocol uses SSL/TLS connection or not.
  40. * @return true if SSL/TLS is used, else false.
  41. */
  42. boolean isSecure();
  43. /**
  44. * Returns what type the protocol is using, Strings or ByteArrays.
  45. * @return the class that the protocol is using.
  46. */
  47. Class<? extends Object> getType();
  48. /**
  49. * Returns the name of the protocol.
  50. * @return name of the protocol
  51. */
  52. @Override
  53. String toString();
  54. }