<commit_before>// Copyright (C) 2014-2015 <NAME> and Contributors (see the CONTRIBUTORS file).

package main

import (
	"crypto/tls"
	"database/sql"
	"encoding/json"
	"log"
	"net"
	"net/http"
	"net/url"
	"time"

	"github.com/golang/groupcache/lru"
	"github.com/juju/ratelimit"
	"github.com/syncthing/syncthing/lib/protocol"
)

type querysrv struct {
	addr     string
	db       *sql.DB
	prep     map[string]*sql.Stmt
	limiter  *lru.Cache
	cert     tls.Certificate
	listener net.Listener
}

type announcement struct {
	Direct []string   `json:"direct"`
	Relays []annRelay `json:"relays"`
}

type annRelay struct {
	URL     string `json:"url"`
	Latency int    `json:"latency"`
}

func (s *querysrv) Serve() {
	s.limiter = lru.New(lruSize)

	tlsCfg := &tls.Config{
		Certificates:           []tls.Certificate{s.cert},
		ClientAuth:             tls.RequestClientCert,
		SessionTicketsDisabled: true,
		MinVersion:             tls.VersionTLS12,
		CipherSuites: []uint16{
			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
			tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
			tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
		},
	}

	http.HandleFunc("/", s.handler)
	http.HandleFunc("/ping", handlePing)

	tlsListener, err := tls.Listen("tcp", s.addr, tlsCfg)
	if err != nil {
		log.Println("Listen:", err)
		return
	}

	s.listener = tlsListener

	srv := &http.Server{
		ReadTimeout:    30 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 2 << 10,
	}

	if err := srv.Serve(tlsListener); err != nil {<commit_msg>Reduce our patience with slow clients somewhat<commit_after>// Copyright (C) 2014-2015 <NAME> and Contributors (see the CONTRIBUTORS file).

package main

import (
	"crypto/tls"
	"database/sql"
	"encoding/json"
	"log"
	"net"
	"net/http"
	"net/url"
	"time"

	"github.com/golang/groupcache/lru"
	"github.com/juju/ratelimit"
	"github.com/syncthing/syncthing/lib/protocol"
)

type querysrv struct {
	addr     string
	db       *sql.DB
	prep     map[string]*sql.Stmt
	limiter  *lru.Cache
	cert     tls.Certificate
	listener net.Listener
}

type announcement struct {
	Direct []string   `json:"direct"`
	Relays []annRelay `json:"relays"`
}

type annRelay struct {
	URL     string `json:"url"`
	Latency int    `json:"latency"`
}

func (s *querysrv) Serve() {
	s.limiter = lru.New(lruSize)

	tlsCfg := &tls.Config{
		Certificates:           []tls.Certificate{s.cert},
		ClientAuth:             tls.RequestClientCert,
		SessionTicketsDisabled: true,
		MinVersion:             tls.VersionTLS12,
		CipherSuites: []uint16{
			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
			tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
			tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
		},
	}

	http.HandleFunc("/", s.handler)
	http.HandleFunc("/ping", handlePing)

	tlsListener, err := tls.Listen("tcp", s.addr, tlsCfg)
	if err != nil {
		log.Println("Listen:", err)
		return
	}

	s.listener = tlsListener

	srv := &http.Server{
		ReadTimeout:    5 * time.Second,
		WriteTimeout:   5 * time.Second,
		MaxHeaderBytes: 1 << 10,
	}

	if err := srv.Serve(tlsListener); err != nil {
{'fraction_non_alphanumeric': 0.12730015082956259, 'fraction_numerical': 0.025339366515837104, 'mean_word_length': 3.757532281205165, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3591644', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1291, 'n_words': 236}