<commit_before>import Foundation
import lwip

public protocol IPStackDelegate: class {
    func didAcceptTCPSocket(sock: TSTCPSocket)
}

func tcpAcceptFn(arg: UnsafeMutablePointer<Void>, pcb: UnsafeMutablePointer<tcp_pcb>, error: err_t) -> err_t {
    return TUNIPStack.stack.didAcceptTCPSocket(pcb, error: error)
}

func outputPCB(interface: UnsafeMutablePointer<netif>, buf: UnsafeMutablePointer<pbuf>, ipaddr: UnsafeMutablePointer<ip_addr_t>) -> err_t {
    TUNIPStack.stack.writePBuf(buf)
    return err_t(ERR_OK)
}

public class TUNIPStack {
    public static var stack = TUNIPStack()

    // The whole stack is running in this dispatch queue.
    let processQueue = dispatch_queue_create("IPStackQueue", DISPATCH_QUEUE_SERIAL)!

    let timer: dispatch_source_t
    let listenPCB: UnsafeMutablePointer<tcp_pcb>

    /// This has to be set before calling `startProcessing()`
    public var tunInterface: TunInterfaceProtocol!

    public weak var delegate: IPStackDelegate?

    // Since all we need is a mock interface, we just use the loopback interface provided by lwip.
    // Do not need to add any interface.<commit_msg>Rename dispatch queue<commit_after>import Foundation
import lwip

public protocol IPStackDelegate: class {
    func didAcceptTCPSocket(sock: TSTCPSocket)
}

func tcpAcceptFn(arg: UnsafeMutablePointer<Void>, pcb: UnsafeMutablePointer<tcp_pcb>, error: err_t) -> err_t {
    return TUNIPStack.stack.didAcceptTCPSocket(pcb, error: error)
}

func outputPCB(interface: UnsafeMutablePointer<netif>, buf: UnsafeMutablePointer<pbuf>, ipaddr: UnsafeMutablePointer<ip_addr_t>) -> err_t {
    TUNIPStack.stack.writePBuf(buf)
    return err_t(ERR_OK)
}

public class TUNIPStack {
    public static var stack = TUNIPStack()

    // The whole stack is running in this dispatch queue.
    let processQueue = dispatch_queue_create("tun2socks.IPStackQueue", DISPATCH_QUEUE_SERIAL)!

    let timer: dispatch_source_t
    let listenPCB: UnsafeMutablePointer<tcp_pcb>

    /// This has to be set before calling `startProcessing()`
    public var tunInterface: TunInterfaceProtocol!

    public weak var delegate: IPStackDelegate?

    // Since all we need is a mock interface, we just use the loopback interface provided by lwip.
    // Do not need to add any interface.
{'fraction_non_alphanumeric': 0.07850877192982456, 'fraction_numerical': 0.0004385964912280702, 'mean_word_length': 4.674129353233831, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '2740265', 'n_tokens_mistral': 713, 'n_tokens_neox': 694, 'n_words': 205}