| 949 | } |
| 950 | |
| 951 | func (s *UdpServer) processACOperation(knkMsg *common.AgentKnockMsg, conn *ACConn, srcAddr *common.NetAddress, dstAddrs []*common.NetAddress, openTime uint32) (artMsg *common.ACOpsResultMsg, err error) { |
| 952 | // should not happen |
| 953 | if knkMsg == nil || conn == nil { |
| 954 | log.Critical("processACOperation with nil input argument") |
| 955 | err = common.ErrInvalidInput |
| 956 | return |
| 957 | } |
| 958 | |
| 959 | artMsg = &common.ACOpsResultMsg{} |
| 960 | if srcAddr == nil || len(dstAddrs) == 0 { |
| 961 | log.Error("[processACOperation] no address specified") |
| 962 | err = common.ErrACEmptyPassAddress |
| 963 | artMsg.ErrCode = common.ErrACEmptyPassAddress.ErrorCode() |
| 964 | artMsg.ErrMsg = err.Error() |
| 965 | return |
| 966 | } |
| 967 | |
| 968 | srcAddrs := []*common.NetAddress{srcAddr} |
| 969 | // check source ip associated address |
| 970 | s.srcIpAssociatedAddrMapMutex.Lock() |
| 971 | asscAddrs, found := s.srcIpAssociatedAddrMap[srcAddr.Ip] |
| 972 | s.srcIpAssociatedAddrMapMutex.Unlock() |
| 973 | if found { |
| 974 | srcAddrs = append(srcAddrs, asscAddrs...) |
| 975 | } |
| 976 | |
| 977 | acAddrStr := conn.ACPeer.RecvAddr().String() |
| 978 | if openTime == 0 { |
| 979 | openTime = DefaultIpOpenTime |
| 980 | } |
| 981 | |
| 982 | aopMsg := &common.ServerACOpsMsg{ |
| 983 | UserId: knkMsg.UserId, |
| 984 | DeviceId: knkMsg.DeviceId, |
| 985 | OrganizationId: knkMsg.OrganizationId, |
| 986 | AuthServiceId: knkMsg.AuthServiceId, |
| 987 | ResourceId: knkMsg.ResourceId, |
| 988 | SourceAddrs: srcAddrs, |
| 989 | DestinationAddrs: dstAddrs, |
| 990 | OpenTime: openTime + ACOpenCompensationTime, // compensate ac open time |
| 991 | } |
| 992 | aopBytes, _ := json.Marshal(aopMsg) |
| 993 | |
| 994 | aopMd := &core.MsgData{ |
| 995 | ConnData: conn.ConnData, |
| 996 | HeaderType: core.NHP_AOP, |
| 997 | CipherScheme: conn.ACCipherScheme, |
| 998 | TransactionId: s.device.NextCounterIndex(), |
| 999 | Compress: true, |
| 1000 | PeerPk: conn.ACPeer.PublicKey(), |
| 1001 | Message: aopBytes, |
| 1002 | ResponseMsgCh: make(chan *core.PacketParserData), |
| 1003 | } |
| 1004 | |
| 1005 | if !s.IsRunning() { |
| 1006 | log.Error("server-agent(%s@%s)-ac(%s#%d@%s)[processACOperation] MsgData channel closed or being closed, skip sending", knkMsg.UserId, srcAddr.String(), conn.ACId, aopMd.TransactionId, acAddrStr) |
| 1007 | err = common.ErrPacketToMessageRoutineStopped |
| 1008 | artMsg.ErrCode = common.ErrPacketToMessageRoutineStopped.ErrorCode() |