<commit_before>package unfiltered.netty

import io.netty.channel.{ ChannelHandlerContext, ChannelInboundHandlerAdapter }
import io.netty.handler.ssl.{ SslHandler, SslHandshakeCompletionEvent }

/** Adds ssl handshaking to a channel handler's #channelConnected method
  * This assumes a SslHandler was added to the underlying ChannelPipeline */
trait Secured extends ChannelInboundHandlerAdapter {
  /** Client code should always pass userEventTriggered events upstream */
  override def userEventTriggered(ctx: ChannelHandlerContext, msg: java.lang.Object): Unit =
    msg match {
      case complete: SslHandshakeCompletionEvent =>
        channelSecured(ctx, complete)
      case _ => ()
    }

  /** Called after a successful Ssl handshake. By default, this does nothing. 
    * Override this for post-handshake behavior. */
  def channelSecured(ctx: ChannelHandlerContext, complete: SslHandshakeCompletionEvent): Unit = ()
}<commit_msg>make secured trait sharable as it maintains no state. also be sure to pass custom user events upstream<commit_after>package unfiltered.netty

import io.netty.channel.{ ChannelHandlerContext, ChannelInboundHandlerAdapter }
import io.netty.handler.ssl.{ SslHandler, SslHandshakeCompletionEvent }
import io.netty.channel.ChannelHandler.Sharable

/** Adds ssl handshaking to a channel handler's #channelConnected method
  * This assumes a SslHandler was added to the underlying ChannelPipeline */
@Sharable // this indicates that the handler is stateless and be called without syncronization
trait Secured extends ChannelInboundHandlerAdapter {
  /** Client code should always pass userEventTriggered events upstream */
  override def userEventTriggered(ctx: ChannelHandlerContext, event: java.lang.Object): Unit =
    event match {
      case complete: SslHandshakeCompletionEvent =>
        channelSecured(ctx, complete)
      case evt =>
        ctx.fireUserEventTriggered(evt)
    }

  /** Called after a successful Ssl handshake. By default, this does nothing but pass the event upstream
    * Override this for post-handshake behavior. */
  def channelSecured(ctx: ChannelHandlerContext, complete: SslHandshakeCompletionEvent): Unit =
    ctx.fireUserEventTriggered(complete)
}
{'fraction_non_alphanumeric': 0.06985128436232538, 'fraction_numerical': 0.0, 'mean_word_length': 4.751295336787565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917688', 'n_tokens_mistral': 580, 'n_tokens_neox': 574, 'n_words': 196}