MCPcopy Create free account
hub / github.com/eventure/hide.client.linux / connect

Method connect

control/methods.go:77–105  ·  view source on GitHub ↗
( writer http.ResponseWriter, request *http.Request )

Source from the content-addressed store, hash-verified

75}
76
77func ( s *Server ) connect( writer http.ResponseWriter, request *http.Request ) {
78 if request.Method != "GET" { http.Error( writer, http.StatusText( http.StatusNotFound ), http.StatusNotFound ); return }
79 select {
80 case s.connectionOpsLock<-struct{}{}: defer func() { <-s.connectionOpsLock }(); break
81 case <-time.NewTimer( time.Second ).C: http.Error( writer, http.StatusText( http.StatusConflict ), http.StatusConflict ); return
82 }
83
84 writer.Header().Add( "content-type", "application/json" )
85 switch code := s.connection.Code(); code {
86 case connection.Routed: break
87 case connection.Clean:
88 if err := s.connection.Init(); err != nil {
89 writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: err.Error() } }.Json() ); return
90 }
91 break
92 default: writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: "bad state: " + code } }.Json() ); return
93 }
94 wg := sync.WaitGroup{}
95 wg.Add( 1 )
96 s.connection.SetConnectNotify( func( err error ) {
97 switch err {
98 case nil: writer.Write( Result{ Result: s.connection.State() }.Json() )
99 default: writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: err.Error() } }.Json() )
100 }
101 wg.Done()
102 } )
103 s.connection.ScheduleConnect( 0 )
104 wg.Wait()
105}
106
107// disconnect is gentle, leaves the client in "routed" state, i.e. leak protection might be active when configured
108func ( s *Server ) disconnect( writer http.ResponseWriter, request *http.Request ) {

Callers

nothing calls this directly

Calls 8

CodeMethod · 0.80
WriteMethod · 0.80
JsonMethod · 0.80
SetConnectNotifyMethod · 0.80
StateMethod · 0.80
ScheduleConnectMethod · 0.80
ErrorMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected