Compare commits
	
		
			1 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3858f7f23a | 
@ -36,16 +36,19 @@ func (s *GRPCServer) Close() {
 | 
				
			|||||||
	s.server.Stop()
 | 
						s.server.Stop()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Verifies the RPC UNIX path is still listening if it exists.
 | 
				
			||||||
func RPCCleanPath(rpcPath string) {
 | 
					func RPCCleanPath(rpcPath string) {
 | 
				
			||||||
	// Check if the RPC socket already exists.
 | 
						// Check if the RPC socket already exists.
 | 
				
			||||||
	_, err := os.Stat(rpcPath)
 | 
						_, err := os.Stat(rpcPath)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		// If the socket exists, see if its listening.
 | 
							// If the socket exists, see if its listening.
 | 
				
			||||||
		_, err = net.Dial("unix", rpcPath)
 | 
							l, err := net.Dial("unix", rpcPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// If its not listening, remove it to allow us to start.
 | 
							// If its not listening, remove it to allow us to start.
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			os.Remove(rpcPath)
 | 
								os.Remove(rpcPath)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								l.Close()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -38,25 +38,25 @@ func (s *GRPCServer) Close() {
 | 
				
			|||||||
	s.server.Stop()
 | 
						s.server.Stop()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Dialer for named pipes to allow connecting GRPC via named pipes.
 | 
				
			||||||
func pipeDialer(ctx context.Context, addr string) (net.Conn, error) {
 | 
					func pipeDialer(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
	// The addr argument passed by gRPC will be the string we pass to grpc.DialContext (e.g., namedPipePath).
 | 
					 | 
				
			||||||
	// winio.DialPipe handles connecting to the named pipe and returns a net.Conn.
 | 
					 | 
				
			||||||
	// You may need to use winio.DialPipeContext for a cancellable context, but DialPipe
 | 
					 | 
				
			||||||
	// is simpler for a basic example and relies on the deadline set by the gRPC call.
 | 
					 | 
				
			||||||
	return winio.DialPipe(addr, nil)
 | 
						return winio.DialPipe(addr, nil)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Verifies the RPC UNIX path is still listening if it exists.
 | 
				
			||||||
func RPCCleanPath(rpcPath string) {
 | 
					func RPCCleanPath(rpcPath string) {
 | 
				
			||||||
	if !strings.HasPrefix(rpcPath, `\\.\`) {
 | 
						if !strings.HasPrefix(rpcPath, `\\.\`) {
 | 
				
			||||||
		// Check if the RPC socket already exists.
 | 
							// Check if the RPC socket already exists.
 | 
				
			||||||
		_, err := os.Stat(rpcPath)
 | 
							_, err := os.Stat(rpcPath)
 | 
				
			||||||
		if err == nil {
 | 
							if err == nil {
 | 
				
			||||||
			// If the socket exists, see if its listening.
 | 
								// If the socket exists, see if its listening.
 | 
				
			||||||
			_, err = net.Dial("unix", rpcPath)
 | 
								l, err := net.Dial("unix", rpcPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// If its not listening, remove it to allow us to start.
 | 
								// If its not listening, remove it to allow us to start.
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				os.Remove(rpcPath)
 | 
									os.Remove(rpcPath)
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									l.Close()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -102,6 +102,7 @@ func NewGRPCClient() (c pb.VxlanClient, conn *grpc.ClientConn, err error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Start an gRPC client connection to the unix socket.
 | 
						// Start an gRPC client connection to the unix socket.
 | 
				
			||||||
	if strings.HasPrefix(config.RPCPath, `\\.\`) {
 | 
						if strings.HasPrefix(config.RPCPath, `\\.\`) {
 | 
				
			||||||
 | 
							// Attempt to connect using named pipes.
 | 
				
			||||||
		dialOption := grpc.WithContextDialer(pipeDialer)
 | 
							dialOption := grpc.WithContextDialer(pipeDialer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		conn, err = grpc.DialContext(
 | 
							conn, err = grpc.DialContext(
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@ -6,7 +6,7 @@ const (
 | 
				
			|||||||
	serviceDisplayName = "Virtual VXLAN"
 | 
						serviceDisplayName = "Virtual VXLAN"
 | 
				
			||||||
	serviceVendor      = "com.mrgeckosmedia"
 | 
						serviceVendor      = "com.mrgeckosmedia"
 | 
				
			||||||
	serviceDescription = "Virtual VXLAN using TUN interfaces"
 | 
						serviceDescription = "Virtual VXLAN using TUN interfaces"
 | 
				
			||||||
	serviceVersion     = "0.2.4"
 | 
						serviceVersion     = "0.2.5"
 | 
				
			||||||
	defaultConfigFile  = "config.yaml"
 | 
						defaultConfigFile  = "config.yaml"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user