class Client:
  def __init__(self, user):
    self.user = user
    self.ip = str(54) + '.' + str(random.randrange(0, 255)) + '.' + str(random.randrange(0, 255)) + '.' + str(random.randrange(0, 255))
    self.connections = []
    self.routerBuffer = []
    self.inbox = {}
    self.transportLayer = Transport(self)
    self.applicationLayer = Application(self)

  # Adds a link between this client and another
  def addConnection(self, client):
    if client == self:
      return
    if client.ip in self.connections:
      return
    self.connections.append(client.ip)

  # Sends a message (tells the application layer to make a packet)
  def sendMessage(self, source, destination, message , time):
    applicationPacket = self.applicationLayer.generatePacket(time, source, destination, message)
    tcpPackets = self.transportLayer.process(applicationPacket, time)

  def __repr__(self):
    return self.ip

  def __str__(self):
    return self.ip + ' - ' + str(self.connections) + " => Router Buffer: " + str(self.routerBuffer) + "  Inbox: " + str(self.inbox)