1
0

node.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package service
  2. import (
  3. "context"
  4. "crypto/sha256"
  5. "crypto/subtle"
  6. "crypto/tls"
  7. "encoding/base64"
  8. "encoding/hex"
  9. "encoding/json"
  10. "errors"
  11. "fmt"
  12. "net"
  13. "net/http"
  14. "net/url"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "github.com/mhsanaei/3x-ui/v3/database"
  19. "github.com/mhsanaei/3x-ui/v3/database/model"
  20. "github.com/mhsanaei/3x-ui/v3/util/common"
  21. "github.com/mhsanaei/3x-ui/v3/util/netsafe"
  22. "github.com/mhsanaei/3x-ui/v3/web/runtime"
  23. )
  24. type HeartbeatPatch struct {
  25. Status string
  26. LastHeartbeat int64
  27. LatencyMs int
  28. XrayVersion string
  29. PanelVersion string
  30. CpuPct float64
  31. MemPct float64
  32. UptimeSecs uint64
  33. LastError string
  34. }
  35. type NodeService struct{}
  36. var nodeHTTPClient = &http.Client{
  37. Transport: &http.Transport{
  38. MaxIdleConns: 64,
  39. MaxIdleConnsPerHost: 4,
  40. IdleConnTimeout: 60 * time.Second,
  41. DialContext: netsafe.SSRFGuardedDialContext,
  42. },
  43. }
  44. // nodeHTTPClientFor returns the HTTP client used to reach a node, honoring its
  45. // per-node TLS verification mode. "verify" (or any http node) uses the shared
  46. // client with default certificate validation. "skip" disables validation.
  47. // "pin" disables the default chain check but verifies the leaf certificate's
  48. // SHA-256 against the stored pin, keeping MITM protection for self-signed certs.
  49. func nodeHTTPClientFor(n *model.Node) (*http.Client, error) {
  50. mode := n.TlsVerifyMode
  51. if mode == "" {
  52. mode = "verify"
  53. }
  54. if mode == "verify" || n.Scheme == "http" {
  55. return nodeHTTPClient, nil
  56. }
  57. tlsCfg := &tls.Config{InsecureSkipVerify: true}
  58. if mode == "pin" {
  59. want, err := decodeCertPin(n.PinnedCertSha256)
  60. if err != nil {
  61. return nil, err
  62. }
  63. tlsCfg.VerifyConnection = func(cs tls.ConnectionState) error {
  64. if len(cs.PeerCertificates) == 0 {
  65. return common.NewError("node presented no certificate")
  66. }
  67. sum := sha256.Sum256(cs.PeerCertificates[0].Raw)
  68. if subtle.ConstantTimeCompare(sum[:], want) != 1 {
  69. return common.NewError("node certificate does not match pinned SHA-256")
  70. }
  71. return nil
  72. }
  73. }
  74. return &http.Client{
  75. Transport: &http.Transport{
  76. MaxIdleConns: 64,
  77. MaxIdleConnsPerHost: 4,
  78. IdleConnTimeout: 60 * time.Second,
  79. DialContext: netsafe.SSRFGuardedDialContext,
  80. TLSClientConfig: tlsCfg,
  81. },
  82. }, nil
  83. }
  84. // decodeCertPin accepts a SHA-256 certificate hash as base64 (the format used
  85. // by Xray's pinnedPeerCertSha256) or hex with optional colons (the openssl
  86. // -fingerprint style) and returns the 32 raw bytes.
  87. func decodeCertPin(s string) ([]byte, error) {
  88. s = strings.TrimSpace(s)
  89. if s == "" {
  90. return nil, common.NewError("certificate pin is empty")
  91. }
  92. if b, err := hex.DecodeString(strings.ReplaceAll(s, ":", "")); err == nil && len(b) == sha256.Size {
  93. return b, nil
  94. }
  95. for _, enc := range []*base64.Encoding{base64.StdEncoding, base64.RawStdEncoding, base64.URLEncoding, base64.RawURLEncoding} {
  96. if b, err := enc.DecodeString(s); err == nil && len(b) == sha256.Size {
  97. return b, nil
  98. }
  99. }
  100. return nil, common.NewError("certificate pin must be a SHA-256 hash (base64 or hex)")
  101. }
  102. // FetchCertFingerprint connects to the node over HTTPS without verifying the
  103. // certificate and returns the leaf certificate's SHA-256 as base64, so the UI
  104. // can offer a "fetch and pin current certificate" action.
  105. func (s *NodeService) FetchCertFingerprint(ctx context.Context, n *model.Node) (string, error) {
  106. addr, err := netsafe.NormalizeHost(n.Address)
  107. if err != nil {
  108. return "", err
  109. }
  110. scheme := n.Scheme
  111. if scheme != "http" && scheme != "https" {
  112. scheme = "https"
  113. }
  114. if scheme != "https" {
  115. return "", common.NewError("certificate pinning is only available for https nodes")
  116. }
  117. if n.Port <= 0 || n.Port > 65535 {
  118. return "", common.NewError("node port must be 1-65535")
  119. }
  120. probeURL := &url.URL{
  121. Scheme: scheme,
  122. Host: net.JoinHostPort(addr, strconv.Itoa(n.Port)),
  123. Path: normalizeBasePath(n.BasePath) + "panel/api/server/status",
  124. }
  125. req, err := http.NewRequestWithContext(
  126. netsafe.ContextWithAllowPrivate(ctx, n.AllowPrivateAddress),
  127. http.MethodGet, probeURL.String(), nil)
  128. if err != nil {
  129. return "", err
  130. }
  131. client := &http.Client{
  132. Transport: &http.Transport{
  133. DialContext: netsafe.SSRFGuardedDialContext,
  134. TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // lgtm[go/disabled-certificate-check]
  135. },
  136. }
  137. resp, err := client.Do(req)
  138. if err != nil {
  139. return "", err
  140. }
  141. defer resp.Body.Close()
  142. if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {
  143. return "", common.NewError("node did not present a TLS certificate")
  144. }
  145. sum := sha256.Sum256(resp.TLS.PeerCertificates[0].Raw)
  146. return base64.StdEncoding.EncodeToString(sum[:]), nil
  147. }
  148. func (s *NodeService) GetAll() ([]*model.Node, error) {
  149. db := database.GetDB()
  150. var nodes []*model.Node
  151. err := db.Model(model.Node{}).Order("id asc").Find(&nodes).Error
  152. if err != nil || len(nodes) == 0 {
  153. return nodes, err
  154. }
  155. type inboundRow struct {
  156. Id int
  157. NodeID int `gorm:"column:node_id"`
  158. }
  159. var inboundRows []inboundRow
  160. if err := db.Table("inbounds").
  161. Select("id, node_id").
  162. Where("node_id IS NOT NULL").
  163. Scan(&inboundRows).Error; err != nil {
  164. return nodes, nil
  165. }
  166. if len(inboundRows) == 0 {
  167. return nodes, nil
  168. }
  169. inboundsByNode := make(map[int][]int, len(nodes))
  170. nodeByInbound := make(map[int]int, len(inboundRows))
  171. for _, row := range inboundRows {
  172. inboundsByNode[row.NodeID] = append(inboundsByNode[row.NodeID], row.Id)
  173. nodeByInbound[row.Id] = row.NodeID
  174. }
  175. type clientCountRow struct {
  176. NodeID int `gorm:"column:node_id"`
  177. Count int `gorm:"column:count"`
  178. }
  179. var clientCounts []clientCountRow
  180. if err := db.Raw(`
  181. SELECT inbounds.node_id AS node_id, COUNT(DISTINCT client_inbounds.client_id) AS count
  182. FROM inbounds
  183. JOIN client_inbounds ON client_inbounds.inbound_id = inbounds.id
  184. WHERE inbounds.node_id IS NOT NULL
  185. GROUP BY inbounds.node_id
  186. `).Scan(&clientCounts).Error; err == nil {
  187. for _, row := range clientCounts {
  188. for _, n := range nodes {
  189. if n.Id == row.NodeID {
  190. n.ClientCount = row.Count
  191. break
  192. }
  193. }
  194. }
  195. }
  196. now := time.Now().UnixMilli()
  197. type trafficRow struct {
  198. InboundID int `gorm:"column:inbound_id"`
  199. Email string
  200. Enable bool
  201. Total int64
  202. Up int64
  203. Down int64
  204. ExpiryTime int64 `gorm:"column:expiry_time"`
  205. }
  206. var trafficRows []trafficRow
  207. inboundIDs := make([]int, 0, len(nodeByInbound))
  208. for id := range nodeByInbound {
  209. inboundIDs = append(inboundIDs, id)
  210. }
  211. if err := db.Table("client_traffics").
  212. Select("inbound_id, email, enable, total, up, down, expiry_time").
  213. Where("inbound_id IN ?", inboundIDs).
  214. Scan(&trafficRows).Error; err == nil {
  215. onlineByNodeSet := s.onlineEmailsByNode()
  216. depletedByNode := make(map[int]int)
  217. onlineByNode := make(map[int]int)
  218. for _, row := range trafficRows {
  219. nodeID, ok := nodeByInbound[row.InboundID]
  220. if !ok {
  221. continue
  222. }
  223. expired := row.ExpiryTime > 0 && row.ExpiryTime <= now
  224. exhausted := row.Total > 0 && row.Up+row.Down >= row.Total
  225. if expired || exhausted || !row.Enable {
  226. depletedByNode[nodeID]++
  227. }
  228. // Scope online by the node the inbound lives on: a client online
  229. // on one node must not count as online on another.
  230. if set, ok := onlineByNodeSet[nodeID]; ok {
  231. if _, isOnline := set[row.Email]; isOnline {
  232. onlineByNode[nodeID]++
  233. }
  234. }
  235. }
  236. for _, n := range nodes {
  237. n.InboundCount = len(inboundsByNode[n.Id])
  238. n.DepletedCount = depletedByNode[n.Id]
  239. n.OnlineCount = onlineByNode[n.Id]
  240. }
  241. }
  242. return nodes, nil
  243. }
  244. func (s *NodeService) onlineEmailsByNode() map[int]map[string]struct{} {
  245. svc := InboundService{}
  246. byNode := svc.GetOnlineClientsByNode()
  247. out := make(map[int]map[string]struct{}, len(byNode))
  248. for nodeID, emails := range byNode {
  249. set := make(map[string]struct{}, len(emails))
  250. for _, email := range emails {
  251. set[email] = struct{}{}
  252. }
  253. out[nodeID] = set
  254. }
  255. return out
  256. }
  257. func (s *NodeService) GetById(id int) (*model.Node, error) {
  258. db := database.GetDB()
  259. n := &model.Node{}
  260. if err := db.Model(model.Node{}).Where("id = ?", id).First(n).Error; err != nil {
  261. return nil, err
  262. }
  263. return n, nil
  264. }
  265. func normalizeBasePath(p string) string {
  266. p = strings.TrimSpace(p)
  267. if p == "" {
  268. return "/"
  269. }
  270. if !strings.HasPrefix(p, "/") {
  271. p = "/" + p
  272. }
  273. if !strings.HasSuffix(p, "/") {
  274. p = p + "/"
  275. }
  276. return p
  277. }
  278. func (s *NodeService) normalize(n *model.Node) error {
  279. n.Name = strings.TrimSpace(n.Name)
  280. n.ApiToken = strings.TrimSpace(n.ApiToken)
  281. if n.Name == "" {
  282. return common.NewError("node name is required")
  283. }
  284. addr, err := netsafe.NormalizeHost(n.Address)
  285. if err != nil {
  286. return common.NewError(err.Error())
  287. }
  288. n.Address = addr
  289. if n.Port <= 0 || n.Port > 65535 {
  290. return common.NewError("node port must be 1-65535")
  291. }
  292. if n.Scheme != "http" && n.Scheme != "https" {
  293. n.Scheme = "https"
  294. }
  295. if n.TlsVerifyMode != "skip" && n.TlsVerifyMode != "pin" {
  296. n.TlsVerifyMode = "verify"
  297. }
  298. n.PinnedCertSha256 = strings.TrimSpace(n.PinnedCertSha256)
  299. if n.TlsVerifyMode == "pin" {
  300. if _, err := decodeCertPin(n.PinnedCertSha256); err != nil {
  301. return common.NewError(err.Error())
  302. }
  303. }
  304. n.BasePath = normalizeBasePath(n.BasePath)
  305. return nil
  306. }
  307. func (s *NodeService) Create(n *model.Node) error {
  308. if err := s.normalize(n); err != nil {
  309. return err
  310. }
  311. db := database.GetDB()
  312. return db.Create(n).Error
  313. }
  314. func (s *NodeService) Update(id int, in *model.Node) error {
  315. if err := s.normalize(in); err != nil {
  316. return err
  317. }
  318. db := database.GetDB()
  319. existing := &model.Node{}
  320. if err := db.Where("id = ?", id).First(existing).Error; err != nil {
  321. return err
  322. }
  323. updates := map[string]any{
  324. "name": in.Name,
  325. "remark": in.Remark,
  326. "scheme": in.Scheme,
  327. "address": in.Address,
  328. "port": in.Port,
  329. "base_path": in.BasePath,
  330. "api_token": in.ApiToken,
  331. "enable": in.Enable,
  332. "allow_private_address": in.AllowPrivateAddress,
  333. "tls_verify_mode": in.TlsVerifyMode,
  334. "pinned_cert_sha256": in.PinnedCertSha256,
  335. }
  336. if err := db.Model(model.Node{}).Where("id = ?", id).Updates(updates).Error; err != nil {
  337. return err
  338. }
  339. if mgr := runtime.GetManager(); mgr != nil {
  340. mgr.InvalidateNode(id)
  341. }
  342. return nil
  343. }
  344. func (s *NodeService) Delete(id int) error {
  345. db := database.GetDB()
  346. if err := db.Where("id = ?", id).Delete(model.Node{}).Error; err != nil {
  347. return err
  348. }
  349. if err := db.Where("node_id = ?", id).Delete(&model.NodeClientTraffic{}).Error; err != nil {
  350. return err
  351. }
  352. if mgr := runtime.GetManager(); mgr != nil {
  353. mgr.InvalidateNode(id)
  354. }
  355. nodeMetrics.drop(nodeMetricKey(id, "cpu"))
  356. nodeMetrics.drop(nodeMetricKey(id, "mem"))
  357. return nil
  358. }
  359. func (s *NodeService) SetEnable(id int, enable bool) error {
  360. db := database.GetDB()
  361. return db.Model(model.Node{}).Where("id = ?", id).Update("enable", enable).Error
  362. }
  363. // GetWebCertFiles asks a node for its own web TLS certificate/key file paths,
  364. // used by "Set Cert from Panel" so a node-assigned inbound gets paths that
  365. // exist on the node rather than the central panel. See issue #4854.
  366. func (s *NodeService) GetWebCertFiles(id int) (*runtime.WebCertFiles, error) {
  367. n, err := s.GetById(id)
  368. if err != nil || n == nil {
  369. return nil, fmt.Errorf("node not found")
  370. }
  371. if !n.Enable {
  372. return nil, fmt.Errorf("node is disabled")
  373. }
  374. mgr := runtime.GetManager()
  375. if mgr == nil {
  376. return nil, fmt.Errorf("runtime manager unavailable")
  377. }
  378. remote, err := mgr.RemoteFor(n)
  379. if err != nil {
  380. return nil, err
  381. }
  382. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  383. defer cancel()
  384. return remote.GetWebCertFiles(ctx)
  385. }
  386. // NodeUpdateResult reports the outcome of triggering a panel self-update on one
  387. // node so the UI can show per-node success/failure for a bulk request.
  388. type NodeUpdateResult struct {
  389. Id int `json:"id"`
  390. Name string `json:"name"`
  391. OK bool `json:"ok"`
  392. Error string `json:"error,omitempty"`
  393. }
  394. // UpdatePanels triggers the official self-updater on each given node. Only
  395. // enabled, online nodes are eligible — an offline node can't be reached, so it
  396. // is reported as skipped rather than silently dropped.
  397. func (s *NodeService) UpdatePanels(ids []int) ([]NodeUpdateResult, error) {
  398. mgr := runtime.GetManager()
  399. if mgr == nil {
  400. return nil, fmt.Errorf("runtime manager unavailable")
  401. }
  402. results := make([]NodeUpdateResult, 0, len(ids))
  403. for _, id := range ids {
  404. n, err := s.GetById(id)
  405. if err != nil || n == nil {
  406. results = append(results, NodeUpdateResult{Id: id, OK: false, Error: "node not found"})
  407. continue
  408. }
  409. res := NodeUpdateResult{Id: id, Name: n.Name}
  410. switch {
  411. case !n.Enable:
  412. res.Error = "node is disabled"
  413. case n.Status != "online":
  414. res.Error = "node is offline"
  415. default:
  416. remote, remoteErr := mgr.RemoteFor(n)
  417. if remoteErr != nil {
  418. res.Error = remoteErr.Error()
  419. break
  420. }
  421. ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
  422. updErr := remote.UpdatePanel(ctx)
  423. cancel()
  424. if updErr != nil {
  425. res.Error = updErr.Error()
  426. } else {
  427. res.OK = true
  428. }
  429. }
  430. results = append(results, res)
  431. }
  432. return results, nil
  433. }
  434. func (s *NodeService) UpdateHeartbeat(id int, p HeartbeatPatch) error {
  435. db := database.GetDB()
  436. updates := map[string]any{
  437. "status": p.Status,
  438. "last_heartbeat": p.LastHeartbeat,
  439. "latency_ms": p.LatencyMs,
  440. "xray_version": p.XrayVersion,
  441. "panel_version": p.PanelVersion,
  442. "cpu_pct": p.CpuPct,
  443. "mem_pct": p.MemPct,
  444. "uptime_secs": p.UptimeSecs,
  445. "last_error": p.LastError,
  446. }
  447. if err := db.Model(model.Node{}).Where("id = ?", id).Updates(updates).Error; err != nil {
  448. return err
  449. }
  450. if p.Status == "online" {
  451. now := time.Unix(p.LastHeartbeat, 0)
  452. nodeMetrics.append(nodeMetricKey(id, "cpu"), now, p.CpuPct)
  453. nodeMetrics.append(nodeMetricKey(id, "mem"), now, p.MemPct)
  454. }
  455. return nil
  456. }
  457. func nodeMetricKey(id int, metric string) string {
  458. return "node:" + strconv.Itoa(id) + ":" + metric
  459. }
  460. func (s *NodeService) AggregateNodeMetric(id int, metric string, bucketSeconds int, maxPoints int) []map[string]any {
  461. return nodeMetrics.aggregate(nodeMetricKey(id, metric), bucketSeconds, maxPoints)
  462. }
  463. func (s *NodeService) Probe(ctx context.Context, n *model.Node) (HeartbeatPatch, error) {
  464. patch := HeartbeatPatch{LastHeartbeat: time.Now().Unix()}
  465. addr, err := netsafe.NormalizeHost(n.Address)
  466. if err != nil {
  467. patch.LastError = err.Error()
  468. return patch, err
  469. }
  470. scheme := n.Scheme
  471. if scheme != "http" && scheme != "https" {
  472. scheme = "https"
  473. }
  474. if n.Port <= 0 || n.Port > 65535 {
  475. patch.LastError = "node port must be 1-65535"
  476. return patch, errors.New(patch.LastError)
  477. }
  478. probeURL := &url.URL{
  479. Scheme: scheme,
  480. Host: net.JoinHostPort(addr, strconv.Itoa(n.Port)),
  481. Path: normalizeBasePath(n.BasePath) + "panel/api/server/status",
  482. }
  483. req, err := http.NewRequestWithContext(
  484. netsafe.ContextWithAllowPrivate(ctx, n.AllowPrivateAddress),
  485. http.MethodGet, probeURL.String(), nil)
  486. if err != nil {
  487. patch.LastError = err.Error()
  488. return patch, err
  489. }
  490. if n.ApiToken != "" {
  491. req.Header.Set("Authorization", "Bearer "+n.ApiToken)
  492. }
  493. req.Header.Set("Accept", "application/json")
  494. client, err := nodeHTTPClientFor(n)
  495. if err != nil {
  496. patch.LastError = err.Error()
  497. return patch, err
  498. }
  499. start := time.Now()
  500. resp, err := client.Do(req)
  501. if err != nil {
  502. patch.LastError = err.Error()
  503. return patch, err
  504. }
  505. defer resp.Body.Close()
  506. patch.LatencyMs = int(time.Since(start) / time.Millisecond)
  507. if resp.StatusCode != http.StatusOK {
  508. patch.LastError = fmt.Sprintf("HTTP %d from remote panel", resp.StatusCode)
  509. return patch, errors.New(patch.LastError)
  510. }
  511. var envelope struct {
  512. Success bool `json:"success"`
  513. Msg string `json:"msg"`
  514. Obj *struct {
  515. CpuPct float64 `json:"cpu"`
  516. Mem struct {
  517. Current uint64 `json:"current"`
  518. Total uint64 `json:"total"`
  519. } `json:"mem"`
  520. Xray struct {
  521. Version string `json:"version"`
  522. } `json:"xray"`
  523. PanelVersion string `json:"panelVersion"`
  524. Uptime uint64 `json:"uptime"`
  525. } `json:"obj"`
  526. }
  527. if err := json.NewDecoder(resp.Body).Decode(&envelope); err != nil {
  528. patch.LastError = "decode response: " + err.Error()
  529. return patch, err
  530. }
  531. if !envelope.Success || envelope.Obj == nil {
  532. patch.LastError = "remote returned success=false: " + envelope.Msg
  533. return patch, errors.New(patch.LastError)
  534. }
  535. o := envelope.Obj
  536. patch.CpuPct = o.CpuPct
  537. if o.Mem.Total > 0 {
  538. patch.MemPct = float64(o.Mem.Current) * 100.0 / float64(o.Mem.Total)
  539. }
  540. patch.XrayVersion = o.Xray.Version
  541. patch.PanelVersion = o.PanelVersion
  542. patch.UptimeSecs = o.Uptime
  543. return patch, nil
  544. }
  545. type ProbeResultUI struct {
  546. Status string `json:"status"`
  547. LatencyMs int `json:"latencyMs"`
  548. XrayVersion string `json:"xrayVersion"`
  549. PanelVersion string `json:"panelVersion"`
  550. CpuPct float64 `json:"cpuPct"`
  551. MemPct float64 `json:"memPct"`
  552. UptimeSecs uint64 `json:"uptimeSecs"`
  553. Error string `json:"error"`
  554. }
  555. func (p HeartbeatPatch) ToUI(ok bool) ProbeResultUI {
  556. r := ProbeResultUI{
  557. LatencyMs: p.LatencyMs,
  558. XrayVersion: p.XrayVersion,
  559. PanelVersion: p.PanelVersion,
  560. CpuPct: p.CpuPct,
  561. MemPct: p.MemPct,
  562. UptimeSecs: p.UptimeSecs,
  563. Error: FriendlyProbeError(p.LastError),
  564. }
  565. if ok {
  566. r.Status = "online"
  567. } else {
  568. r.Status = "offline"
  569. }
  570. return r
  571. }
  572. func FriendlyProbeError(msg string) string {
  573. if strings.Contains(msg, "server gave HTTP response to HTTPS client") {
  574. return "the server speaks HTTP, not HTTPS; set the node scheme to http"
  575. }
  576. return msg
  577. }