Skip to content

Commit

Permalink
remove support for route switching, which mobile doesn't use
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 19, 2024
1 parent 3670e3f commit 7e5f50e
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 32 deletions.
5 changes: 0 additions & 5 deletions src/main/scala/Clients.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ object Clients:
enum Control:
case Start(behavior: ClientBehavior, promise: Promise[Client])
case Stop(client: Client)
case Switch(client: Client, behavior: ClientBehavior, promise: Promise[Client])

def behavior =
Behaviors.receive[Control]: (ctx, msg) =>
msg match
case Control.Start(behavior, promise) =>
promise success ctx.spawnAnonymous(behavior)
Behaviors.same
case Control.Switch(client, behavior, promise) =>
ctx.stop(client)
promise success ctx.spawnAnonymous(behavior)
Behaviors.same
case Control.Stop(client) =>
ctx.stop(client)
Behaviors.same
3 changes: 0 additions & 3 deletions src/main/scala/ipc/ClientIn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ object ClientIn:

def racerState(data: JsonString) = payload("racerState", data)

case class SwitchResponse(uri: lila.ws.util.RequestUri, status: Int) extends ClientIn:
def write = cliMsg("switch", Json.obj("uri" -> uri, "status" -> status))

private val destsRemover = ""","dests":\{[^\}]+}""".r

private def cliMsg[A: Writes](t: String, data: A): String = cliMsg(t, Json.toJson(data))
Expand Down
7 changes: 0 additions & 7 deletions src/main/scala/ipc/ClientOut.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ object ClientOut:

case object Ignore extends ClientOutSite

case class Switch(uri: lila.ws.util.RequestUri) extends ClientOutSite

// lobby

case class Idle(value: Boolean, payload: JsValue) extends ClientOutLobby
Expand Down Expand Up @@ -260,11 +258,6 @@ object ClientOut:
case "racerJoin" => Some(RacerJoin)
case "racerStart" => Some(RacerStart)

case "switch" =>
for
data <- o obj "d"
uri <- data.get[lila.ws.util.RequestUri]("uri")
yield Switch(uri)
case "wrongHole" => Some(WrongHole)
case _ => None
} getOrElse Unexpected(o)
Expand Down
12 changes: 0 additions & 12 deletions src/main/scala/netty/ActorChannelConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ final private class ActorChannelConnector(router: Router, clients: ActorRef[Clie
clients ! Clients.Control.Stop(client)
}

def switch(client: Client, endpoint: Endpoint, channel: Channel)(uri: RequestUri) =
router(endpoint.header.switch(uri)).foreach:
case Left(status) => client ! ClientIn.SwitchResponse(uri, status.code)
case Right(newEndpoint) =>
val clientPromise = Promise[Client]()
val emitter = emitToChannel(channel)
val behavior = newEndpoint.behavior(emitter)
clients ! Clients.Control.Switch(client, behavior, clientPromise)
channel.attr(key.endpoint).set(newEndpoint)
channel.attr(key.client).set(clientPromise.future)
emitter(ClientIn.SwitchResponse(uri, 200))

private def emitToChannel(channel: Channel): ClientEmit =
case ipc.ClientIn.Disconnect =>
channel.writeAndFlush(CloseWebSocketFrame()).addListener(ChannelFutureListener.CLOSE)
Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/netty/FrameHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ final private class FrameHandler(connector: ActorChannelConnector)(using Executo
else
ClientOut parse txt foreach:

case ClientOut.Switch(uri) if endpoint != null =>
withClientOf(ctx.channel) { connector.switch(_, endpoint, ctx.channel)(uri) }

case ClientOut.Unexpected(msg) =>
Monitor.clientOutUnexpected.increment()
logger.info(s"Unexpected $msg")
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/util/RequestHeader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ object RequestUri extends OpaqueString[RequestUri]

final class RequestHeader(val uri: RequestUri, headers: HttpHeaders):

def switch(uri: RequestUri): RequestHeader = RequestHeader(uri, headers)

val (path, parameters) =
val qsd = QueryStringDecoder(uri.value)
(qsd.path, qsd.parameters)
Expand Down Expand Up @@ -52,4 +50,6 @@ final class RequestHeader(val uri: RequestUri, headers: HttpHeaders):

def name: String = s"$uri UA: $userAgent"

def host: String = header(HttpHeaderNames.HOST) getOrElse "?"

override def toString = s"$name origin: $origin"

0 comments on commit 7e5f50e

Please sign in to comment.