MCPcopy Index your code
hub / github.com/coder/coder / NewServer

Function NewServer

agent/agentssh/agentssh.go:162–323  ·  view source on GitHub ↗
(ctx context.Context, logger slog.Logger, prometheusRegistry *prometheus.Registry, fs afero.Fs, execer agentexec.Execer, config *Config)

Source from the content-addressed store, hash-verified

160}
161
162func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prometheus.Registry, fs afero.Fs, execer agentexec.Execer, config *Config) (*Server, error) {
163 if config == nil {
164 config = &Config{}
165 }
166 if config.X11DisplayOffset == nil {
167 offset := X11DefaultDisplayOffset
168 config.X11DisplayOffset = &offset
169 }
170 if config.X11MaxPort == nil {
171 maxPort := X11MaxPort
172 config.X11MaxPort = &maxPort
173 }
174 if config.UpdateEnv == nil {
175 config.UpdateEnv = func(current []string) ([]string, error) { return current, nil }
176 }
177 if config.MOTDFile == nil {
178 config.MOTDFile = func() string { return "" }
179 }
180 if config.AnnouncementBanners == nil {
181 config.AnnouncementBanners = func() *[]codersdk.BannerConfig { return &[]codersdk.BannerConfig{} }
182 }
183 if config.WorkingDirectory == nil {
184 config.WorkingDirectory = func() string {
185 home, err := userHomeDir()
186 if err != nil {
187 return ""
188 }
189 return home
190 }
191 }
192 if config.ReportConnection == nil {
193 config.ReportConnection = func(uuid.UUID, MagicSessionType, string) func(int, string) { return func(int, string) {} }
194 }
195
196 forwardHandler := &ssh.ForwardedTCPHandler{}
197 unixForwardHandler := newForwardedUnixHandler(logger, config.BlockReversePortForwarding)
198
199 metrics := newSSHServerMetrics(prometheusRegistry)
200 s := &Server{
201 Execer: execer,
202 listeners: make(map[net.Listener]struct{}),
203 fs: fs,
204 conns: make(map[net.Conn]struct{}),
205 sessions: make(map[ssh.Session]struct{}),
206 processes: make(map[*os.Process]struct{}),
207 logger: logger,
208
209 config: config,
210
211 metrics: metrics,
212 x11Forwarder: &x11Forwarder{
213 logger: logger,
214 x11HandlerErrors: metrics.x11HandlerErrors,
215 fs: fs,
216 displayOffset: *config.X11DisplayOffset,
217 maxPort: *config.X11MaxPort,
218 sessions: make(map[*x11Session]struct{}),
219 connections: make(map[net.Conn]struct{}),

Callers 10

initMethod · 0.92
setupFunction · 0.92
TestServer_X11Function · 0.92
TestNewServer_SignalFunction · 0.92
Test_sessionStart_orphanFunction · 0.70

Calls 11

newForwardedUnixHandlerFunction · 0.85
newSSHServerMetricsFunction · 0.85
directStreamLocalHandlerFunction · 0.85
DurationMethod · 0.80
userHomeDirFunction · 0.70
AddMethod · 0.65
RemoteAddrMethod · 0.45
LocalAddrMethod · 0.45
ErrorMethod · 0.45
InfoMethod · 0.45

Tested by 9

setupFunction · 0.74
TestServer_X11Function · 0.74
TestNewServer_SignalFunction · 0.74
Test_sessionStart_orphanFunction · 0.56