-
Notifications
You must be signed in to change notification settings - Fork 153
/
http.go
106 lines (96 loc) · 2.7 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Package ais provides core functionality for the AIStore object storage.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
*/
package ais
import (
"net/http"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
)
type global struct {
netServ struct {
pub *netServer
control *netServer
data *netServer
pub2 *netServer
}
client struct {
control *http.Client // http client for intra-cluster comm
data *http.Client // http client to execute target <=> target GET & PUT (object)
}
}
var g global
func handlePub(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
g.netServ.pub.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.pub.muxers[v].HandleFunc(path+"/", handler)
}
}
}
func handleControl(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
g.netServ.control.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.control.muxers[v].HandleFunc(path+"/", handler)
}
}
}
func handleData(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
g.netServ.data.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.data.muxers[v].HandleFunc(path+"/", handler)
}
}
}
func initCtrlClient(config *cmn.Config) {
const (
defaultControlWriteBufferSize = 16 * cos.KiB // for more defaults see cmn/network.go
defaultControlReadBufferSize = 16 * cos.KiB
)
cargs := cmn.TransportArgs{
Timeout: config.Client.Timeout.D(),
WriteBufferSize: defaultControlWriteBufferSize,
ReadBufferSize: defaultControlReadBufferSize,
}
if config.Net.HTTP.UseHTTPS {
g.client.control = cmn.NewIntraClientTLS(cargs, config)
} else {
g.client.control = cmn.NewClient(cargs)
}
}
// wbuf/rbuf - when not configured use AIS defaults (to override the usual 4KB)
func initDataClient(config *cmn.Config) {
wbuf, rbuf := config.Net.HTTP.WriteBufferSize, config.Net.HTTP.ReadBufferSize
if wbuf == 0 {
wbuf = cmn.DefaultWriteBufferSize
}
if rbuf == 0 {
rbuf = cmn.DefaultReadBufferSize
}
cargs := cmn.TransportArgs{
Timeout: config.Client.TimeoutLong.D(),
WriteBufferSize: wbuf,
ReadBufferSize: rbuf,
}
if config.Net.HTTP.UseHTTPS {
g.client.data = cmn.NewIntraClientTLS(cargs, config)
} else {
g.client.data = cmn.NewClient(cargs)
}
}
func shuthttp() {
config := cmn.GCO.Get()
g.netServ.pub.shutdown(config)
if g.netServ.pub2 != nil {
g.netServ.pub2.shutdown(config)
}
if config.HostNet.UseIntraControl {
g.netServ.control.shutdown(config)
}
if config.HostNet.UseIntraData {
g.netServ.data.shutdown(config)
}
}