Przeglądaj źródła

feat: remote debugging

Yeuoly 1 rok temu
rodzic
commit
17f741634d

+ 2 - 0
internal/core/plugin_manager/lifetime.go

@@ -12,6 +12,8 @@ func lifetime(config *app.Config, r entities.PluginRuntimeInterface) {
 	start_failed_times := 0
 	configuration := r.Configuration()
 
+	log.Info("new plugin logged in: %s", configuration.Identity())
+
 	// store plugin runtime
 	m.Store(configuration.Identity(), r)
 	defer m.Delete(configuration.Identity())

+ 8 - 2
internal/core/plugin_manager/remote_manager/hooks.go

@@ -83,7 +83,7 @@ func (s *DifyServer) OnClose(c gnet.Conn, err error) (action gnet.Action) {
 	s.plugins_lock.Unlock()
 
 	// close plugin
-	plugin.close()
+	plugin.onDisconnected()
 
 	return gnet.None
 }
@@ -117,14 +117,20 @@ func (s *DifyServer) OnTraffic(c gnet.Conn) (action gnet.Action) {
 
 func (s *DifyServer) onMessage(runtime *RemotePluginRuntime, message []byte) {
 	// handle message
+	if runtime.handshake_failed {
+		// do nothing if handshake has failed
+		return
+	}
+
 	if !runtime.handshake {
 		key := string(message)
 
 		info, err := GetConnectionInfo(key)
 		if err == cache.ErrNotFound {
 			// close connection if handshake failed
-			runtime.conn.Write([]byte("handshake failed\n"))
+			runtime.conn.Write([]byte("handshake failed, invalid key\n"))
 			runtime.conn.Close()
+			runtime.handshake_failed = true
 			return
 		} else if err != nil {
 			// close connection if handshake failed

+ 3 - 2
internal/core/plugin_manager/remote_manager/type.go

@@ -29,7 +29,8 @@ type RemotePluginRuntime struct {
 	last_active_at time.Time
 
 	// hand shake process completed
-	handshake bool
+	handshake        bool
+	handshake_failed bool
 
 	// registration transferred
 	registration_transferred bool
@@ -55,7 +56,7 @@ func (r *RemotePluginRuntime) removeCallback(session_id string) {
 	r.callbacks_lock.Unlock()
 }
 
-func (r *RemotePluginRuntime) close() {
+func (r *RemotePluginRuntime) onDisconnected() {
 	// close shutdown channel to notify all waiting routines
 	close(r.shutdown_chan)
 

+ 0 - 1
internal/core/plugin_manager/watcher.go

@@ -68,7 +68,6 @@ func handleNewPlugins(config *app.Config) {
 			continue
 		}
 
-		log.Info("loaded plugin: %s", plugin.Config.Identity())
 		routine.Submit(func() {
 			lifetime(config, plugin_interface)
 		})