config

package
v0.0.0-...-a08ad04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config 全局配置集

Index

Constants

View Source
const (
	ServerPort     = 7788 // 默认服务端口(TCP)
	RemotePort     = 7788 // 远端目标端口(TCP)
	UDPListen      = 7080 // 本地 NAT 类型探测监听端口
	UDPLiving      = 7181 // 本地 NAT 生命期探测监听端口
	MaxFinders     = 10   // 组网节点连接数
	PeersHelp      = 8    // 上线协助发送条目数
	MaxApps        = 500  // 每种应用默认的节点连接数上限
	ListFindings   = 40   // 本类节点候选名单长度
	BufferSize     = 1024 // 连接读写缓冲区大小
	PeerFindRange  = 200  // 节点寻找的范围(基于起点)
	STUNPeerAmount = 5    // 打洞协助连系的节点数
	STUNLiving     = true // 是否启动 STUN:Live 服务(NAT生命期探测)
	STUNClient     = true // 是否需要NAT层级&生存期探测
)

基本配置常量。

View Source
const (
	SomeFindings    = 10                // 本类端组网发送条目数
	AppServerTCP    = 6                 // 应用端请求TCP服务器节点数量
	STUNTryMax      = 4                 // 打洞协助单次失败再尝试最大次数
	FinderPatrol    = time.Minute * 10  // 本类节点连接切换巡查间隔
	ShortlistPatrol = time.Minute * 6   // 后续池节点在线巡查间隔
	BanExpired      = time.Hour * 4     // 恶意节点禁闭期限
	ApplierPatrol   = time.Minute * 12  // 应用连接池巡查间隔
	ApplierExpired  = time.Minute * 150 // 应用端在线最长时间(2.5h)
)

开发配置常量 部分值关系到安全性,不提供外部可配置。

View Source
const (
	Kind    = "findings" // 基础类别
	AppName = "z"        // 本服务实现名
	User    = "thanks"   // 本节点的身份ID(非群组成员可任意)
)

本系统(findings:z)

View Source
const (
	LogsDirname  = "logs"         // 默认日志根目录
	LogFile      = "findings.log" // 主程序日志
	LogPeerFile  = "peers.log"    // 有效连接节点历史
	LogDebugFile = "debug.log"    // 调试日志
)

日志文件名

Variables

This section is empty.

Functions

func Bans

func Bans() (map[string]time.Time, error)

Bans 获取用户配置的禁闭节点集(本网)。 配置文件 bans.json,存在于应用程序的安装目录之下。 注: 地址应当格式正确,无空格。

func Peers

func Peers() (map[netip.Addr]*Peer, error)

Peers 获取用户配置的节点IP信息集。 配置文件 ~/.findings/peers.json,内容可能由App发布时配置,或用户自己修改配置。 其中的IP应当至少是曾经有效的,其也可以作为 find.PointIPs 中的起点IP。 返回的集合中排除了重复的IP地址。

func Services

func Services() (map[string]string, error)

Services 读取服务配置集 服务器支持的应用类型名称,以及可受益的账户地址。 对于提供了服务但没有相应区块链收益地址的,账户设置为空串。 配置文件 ~/.findings/services.json

Types

type Config

type Config struct {
	ServerPort     int    `json:"server_port"`           // 本地服务端口
	RemotePort     int    `json:"remote_port,omitempty"` // 远端节点服务端口(7788|443|0|...)
	UDPListen      int    `json:"udp_listen"`            // 本地 NAT 类型探测监听端口
	UDPLiving      int    `json:"udp_living"`            // 本地 NAT 生命期探测监听端口
	LogDir         string `json:"log_dir"`               // 日志根目录
	Findings       int    `json:"findings"`              // 同时连接的本类节点数
	PeersHelp      int    `json:"peers_help"`            // 上线帮助发送条目数
	ConnApps       int    `json:"applications"`          // 可同时连接的应用端数量上限
	Shortlist      int    `json:"shortlist"`             // 本类节点候选名单长度
	BufferSize     int    `json:"buffer_size,omitempty"` // 连接读写缓冲区大小
	PeerFindRange  int    `json:"peers_range"`           // 基于起点,节点寻找的范围
	STUNPeerAmount int    `json:"stun_peer_amount"`      // 打洞协助连接节点数
	STUNLiving     bool   `json:"stun_living"`           // 是否启动全局 UDP:STUN 服务
	STUNClient     bool   `json:"stun_client"`           // 是否需要NAT层级&生存期探测
}

Config 基础配置。 通常来说,直接在公网上的节点应当配置 ServerPort 为标准端口7788或443, 这样方便新上线的节点寻找。 对于处于NAT之后的内网节点,端口是任意的,它们通常作为在候选名单或当前连接的已知节点存在。 RemotePort 用于新节点初始上线时的暴力发现, 仅在App内置节点已不可用,且也没有其它可连接的节点配置时才需要。

func Base

func Base() (*Config, error)

Base 获取基础配置。 用户的配置文件为 ~/.findings/config.json

type Peer

type Peer struct {
	IP   netip.Addr `json:"ip"`   // 公网IP
	Port uint16     `json:"port"` // 公网端口
}

Peer 端点类型。 仅用于读取用户的节点配置。

func (*Peer) String

func (p *Peer) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL