<commit_before>// +build json

package internet

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"strings"

	v2net "github.com/v2ray/v2ray-core/common/net"
)

func (this *TLSSettings) UnmarshalJSON(data []byte) error {
	type JSONCertConfig struct {
		CertFile string `json:"certificateFile"`
		KeyFile  string `json:"keyFile"`
	}
	type JSONConfig struct {
		Insecure bool              `json:"allowInsecure"`
		Certs    []*JSONCertConfig `json:"certificates"`
	}
	jsonConfig := new(JSONConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return err
	}
	this.Certs = make([]tls.Certificate, len(jsonConfig.Certs))
	for idx, certConf := range jsonConfig.Certs {
		cert, err := tls.LoadX509KeyPair(certConf.CertFile, certConf.KeyFile)
		if err != nil {
			return errors.New("Internet|TLS: Failed to load certificate file: " + err.Error())
		}
		this.Certs[idx] = cert
	}
	this.AllowInsecure = jsonConfig.Insecure
	return nil
}

func (this *StreamSettings) UnmarshalJSON(data []byte) error {
	type JSONConfig struct {
		Network     v2net.NetworkList `json:"network"`
		Security    string            `json:"security"`
		TLSSettings *TLSSettings      `json:"tlsSettings"`
	}
	this.Type = StreamConnectionTypeRawTCP
	jsonConfig := new(JSONConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return err
	}
	if jsonConfig.Network.HasNetwork(v2net.KCPNetwork) {
		this.Type |= StreamConnectionTypeKCP
	}
	if jsonConfig.Network.HasNetwork(v2net.TCPNetwork) {
		this.Type |= StreamConnectionTypeTCP
	}
	this.Security = StreamSecurityTypeNone
	if strings.ToLower(jsonConfig.Security) == "tls" {
		this.Security = StreamSecurityTypeTLS
	}
	if jsonConfig.TLSSettings != nil {
		this.TLSSettings = jsonConfig.TLSSettings
	}
	return nil
}
<commit_msg>Load Websocket Streamtype from json<commit_after>// +build json

package internet

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"strings"

	v2net "github.com/v2ray/v2ray-core/common/net"
)

func (this *TLSSettings) UnmarshalJSON(data []byte) error {
	type JSONCertConfig struct {
		CertFile string `json:"certificateFile"`
		KeyFile  string `json:"keyFile"`
	}
	type JSONConfig struct {
		Insecure bool              `json:"allowInsecure"`
		Certs    []*JSONCertConfig `json:"certificates"`
	}
	jsonConfig := new(JSONConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return err
	}
	this.Certs = make([]tls.Certificate, len(jsonConfig.Certs))
	for idx, certConf := range jsonConfig.Certs {
		cert, err := tls.LoadX509KeyPair(certConf.CertFile, certConf.KeyFile)
		if err != nil {
			return errors.New("Internet|TLS: Failed to load certificate file: " + err.Error())
		}
		this.Certs[idx] = cert
	}
	this.AllowInsecure = jsonConfig.Insecure
	return nil
}

func (this *StreamSettings) UnmarshalJSON(data []byte) error {
	type JSONConfig struct {
		Network     v2net.NetworkList `json:"network"`
		Security    string            `json:"security"`
		TLSSettings *TLSSettings      `json:"tlsSettings"`
	}
	this.Type = StreamConnectionTypeRawTCP
	jsonConfig := new(JSONConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return err
	}
	if jsonConfig.Network.HasNetwork(v2net.KCPNetwork) {
		this.Type |= StreamConnectionTypeKCP
	}
	if jsonConfig.Network.HasNetwork(v2net.WSNetwork) {
		this.Type |= StreamConnectionTypeWebSocket
	}
	if jsonConfig.Network.HasNetwork(v2net.TCPNetwork) {
		this.Type |= StreamConnectionTypeTCP
	}
	this.Security = StreamSecurityTypeNone
	if strings.ToLower(jsonConfig.Security) == "tls" {
		this.Security = StreamSecurityTypeTLS
	}
	if jsonConfig.TLSSettings != nil {
		this.TLSSettings = jsonConfig.TLSSettings
	}
	return nil
}

{'fraction_non_alphanumeric': 0.1191582399562722, 'fraction_numerical': 0.005192675594424706, 'mean_word_length': 4.335276967930029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7542313', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1216, 'n_words': 262}