func BuildCircuit(slc []dirclient.KNode, subchannel int) (io.ReadWriteCloser, error) {
	// this returns a checker whether a public key is valid
	pubkey_checker := func(hsh string) func([]byte) bool {
		return func([]byte) bool { return true }

		return func(xaxa []byte) bool {
			hashed := hash_base32(xaxa)
			return subtle.ConstantTimeCompare([]byte(hashed), []byte(hsh)) == 1
		}
	}

	// circuit-building loop
	gwire, err := dialer.Dial(Old2New(slc[0].Address))
	if err != nil {
		return nil, err
	}
	wire, err := kiss.TransportHandshake(kiss.GenerateDHKeys(),
		gwire, pubkey_checker(slc[0].PublicKey))
	if err != nil {
		gwire.Close()
		return nil, err
	}
	for _, ele := range slc[1:] {
		kilog.Debug("Connecting to node %v...", string([]byte(ele.PublicKey)[:10]))
		// extend wire
		_, err = wire.Write(append([]byte{byte(len(ele.PublicKey))}, ele.PublicKey...))
		if err != nil {
			gwire.Close()
			return nil, err
		}

		verifier := pubkey_checker(ele.PublicKey)
		// at this point wire is raw (well unobfs) connection to next
		wire, err = kiss.TransportHandshake(kiss.GenerateDHKeys(), wire, verifier)
		if err != nil {
			kilog.Debug("Died when transport at %s", ele.PublicKey)
			gwire.Close()
			return nil, err
		}
		kilog.Debug("Connected to node %v!", string([]byte(ele.PublicKey)[:10]))
	}
	_, err = wire.Write([]byte{byte(subchannel)})
	if err != nil {
		gwire.Close()
		return nil, err
	}
	kilog.Debug("Opened subchannel %d", subchannel)
	return wire, nil
}
func sc_server_real_handler(_wire io.ReadWriteCloser) (err error) {
	wire, err := kiss.TransportHandshake(MasterKey, _wire,
		func([]byte) bool { return true })
	if err != nil {
		kilog.Debug("failed the transport handshake")
		return err
	}
	thing := make([]byte, 1)
	_, err = io.ReadFull(wire, thing)
	if err != nil {
		kilog.Debug("failed the readfull")
		return err
	}
	if thing[0] == 0 {
		// Terminate
		if !MasterConfig.General.IsExit {
			return nil
		}
		kilog.Debug("opening legacy (stew) circuit")
		e2e_server_handler_old(wire)
	} else if thing[0] == 255 {
		// Terminate with kinda old
		if !MasterConfig.General.IsExit {
			return nil
		}
		kilog.Debug("opening kinda old circuit")
		e2e_server_kinda_old_handler(wire)
	} else if thing[0] == 254 {
		// Terminate with new
		if !MasterConfig.General.IsExit {
			return nil
		}
		kilog.Debug("opening circuit")
		e2e_server_handler(wire)
	} else {
		xaxa := make([]byte, thing[0])
		_, err := io.ReadFull(wire, xaxa)
		if err != nil {
			return err
		}
		key := string(xaxa)
		qqq := dirclient.PKeyLookup(key)
		if qqq == nil {
			kilog.Debug("Cannot find %s in %v", xaxa, dirclient.KDirectory)
			dirclient.RefreshDirectory()
			qqq = dirclient.PKeyLookup(key)
			if qqq == nil {
				return nil
			}
		}
		kilog.Debug("Continuing to %s", qqq.Address)
		remm, err := circuitry.Dialer.Dial(circuitry.Old2New(qqq.Address))
		if err != nil {
			return err
		}
		go func() {
			io.Copy(wire, remm)
			wire.Close()
		}()
		io.Copy(remm, wire)
		remm.Close()
	}
	return io.EOF
}