MCPcopy
hub / github.com/ph4ntonn/Stowaway / normalReconnActiveReconn

Function normalReconnActiveReconn

agent/process/offline.go:232–310  ·  view source on GitHub ↗
(options *initial.Options, proxy share.Proxy)

Source from the content-addressed store, hash-verified

230}
231
232func normalReconnActiveReconn(options *initial.Options, proxy share.Proxy) net.Conn {
233 var sMessage, rMessage protocol.Message
234
235 hiMess := &protocol.HIMess{
236 GreetingLen: uint16(len("Shhh...")),
237 Greeting: "Shhh...",
238 UUIDLen: uint16(len(global.G_Component.UUID)),
239 UUID: global.G_Component.UUID,
240 IsAdmin: 0,
241 IsReconnect: 1,
242 }
243
244 header := &protocol.Header{
245 Sender: global.G_Component.UUID,
246 Accepter: protocol.ADMIN_UUID,
247 MessageType: protocol.HI,
248 RouteLen: uint32(len([]byte(protocol.TEMP_ROUTE))),
249 Route: protocol.TEMP_ROUTE,
250 }
251
252 for {
253 var (
254 conn net.Conn
255 err error
256 )
257
258 if proxy == nil {
259 conn, err = net.Dial("tcp", options.Connect)
260 } else {
261 conn, err = proxy.Dial()
262 }
263
264 if err != nil {
265 time.Sleep(time.Duration(options.Reconnect) * time.Second)
266 continue
267 }
268
269 if err := share.ActivePreAuth(conn); err != nil {
270 conn.Close()
271 time.Sleep(time.Duration(options.Reconnect) * time.Second)
272 continue
273 }
274
275 if global.G_TLSEnable {
276 var tlsConfig *tls.Config
277 tlsConfig, err = transport.NewClientTLSConfig(options.Domain)
278 if err != nil {
279 conn.Close()
280 time.Sleep(time.Duration(options.Reconnect) * time.Second)
281 continue
282 }
283 conn = transport.WrapTLSClientConn(conn, tlsConfig)
284 }
285
286 sMessage = protocol.PrepareAndDecideWhichSProtoToUpper(conn, options.Secret, protocol.TEMP_UUID)
287
288 protocol.ConstructMessage(sMessage, header, hiMess, false)
289 sMessage.SendMessage()

Callers 1

upstreamOfflineFunction · 0.85

Calls 9

SendMessageMethod · 0.95
ActivePreAuthFunction · 0.92
NewClientTLSConfigFunction · 0.92
WrapTLSClientConnFunction · 0.92
ConstructMessageFunction · 0.92
DestructMessageFunction · 0.92
DialMethod · 0.65

Tested by

no test coverage detected