     }
     
     open func startAdvertising(_ role: RoleType) {
-        if self.advertising == true {
+        if let role = self.advertising {
             NSLog("BluepeerObject: Already advertising (no-op)")
             return
         }

            return
        }
        let peer = self.peers[peerIndex]
        let oldState = peer.state
        peer.state = .notConnected
        peer.keepaliveTimer?.invalidate()
        peer.keepaliveTimer = nil
        peer.socket = nil
        sock.delegate = nil
        NSLog("BluepeerObject: \(peer.displayName) @ \(peer.socket?.connectedHost) disconnected.")
        switch oldState {
        case .connected:
            self.peers.remove(at: peerIndex)
            self.dispatch_on_delegate_queue({
                self.sessionDelegate?.peerDidDisconnect?(peer.role, peer: peer)
            })
        case .notConnected:
            self.peers.remove(at: peerIndex)
            assert(false, "ERROR: state is being tracked wrong")
        case .connecting, .awaitingAuth:
            // don't remove peer in this case

    open var bluetoothState : BluetoothState = .unknown
    var bluetoothPeripheralManager: CBPeripheralManager
    open var bluetoothBlock: ((_ bluetoothState: BluetoothState) -> Void)?
    open var disconnectOnBackground: Bool = false
    let headerTerminator: Data = "\r\n\r\n".data(using: String.Encoding.utf8)! // same as HTTP. But header content here is just a number, representing the byte count of the incoming nsdata.
    let keepAliveHeader: Data = "0 ! 0 ! 0 ! 0 ! 0 ! 0 ! 0 ! ".data(using: String.Encoding.utf8)! // A special header kept to avoid timeouts
    let socketQueue = DispatchQueue(label: "xaphod.bluepeer.socketQueue", attributes: [])
