@@ -14,6 +14,7 @@ import (
14
14
"vikingPingvin/locker/locker/messaging"
15
15
"vikingPingvin/locker/locker/messaging/protobuf"
16
16
17
+ "github.com/rs/xid"
17
18
"github.com/rs/zerolog/log"
18
19
"google.golang.org/protobuf/proto"
19
20
)
@@ -26,6 +27,7 @@ type InputData struct {
26
27
FileInput string
27
28
FileName string
28
29
FileHash []byte
30
+ ID xid.ID
29
31
}
30
32
31
33
type Agent interface {
@@ -52,7 +54,7 @@ func (a ArtifactAgent) Start(inputData *InputData) bool {
52
54
parseAndSendPayload (connection , inputData )
53
55
54
56
// Listen for ACK from server
55
- listenForACK (connection )
57
+ listenForACK (connection , inputData )
56
58
57
59
return true
58
60
}
@@ -71,10 +73,11 @@ func parseAndSendMetaData(connection net.Conn, inputData *InputData) (fileInfo o
71
73
Str ("file name" , fileInfo .Name ()).
72
74
Str ("size" , fmt .Sprintf ("%d" , fileInfo .Size ())).
73
75
Str ("hash" , fmt .Sprintf ("%v" , inputData .FileHash )).
76
+ Str ("id" , inputData .ID .String ()).
74
77
Msg ("Artifact metadata parsing finished" )
75
78
76
79
message , err := messaging .CreateMessage_FileMeta (
77
- 2234 ,
80
+ inputData . ID . Bytes () ,
78
81
protobuf .MessageType_META ,
79
82
"test_namespace" ,
80
83
"test_project" ,
@@ -111,7 +114,7 @@ func parseAndSendPayload(connection net.Conn, inputData *InputData) {
111
114
isPayloadFinal = true
112
115
// Send terminating payload protobuf message
113
116
terminalMessage , err := messaging .CreateMessage_FilePackage (
114
- 2234 ,
117
+ inputData . ID . Bytes () ,
115
118
protobuf .MessageType_PACKAGE ,
116
119
make ([]byte , 1 ),
117
120
isPayloadFinal ,
@@ -124,7 +127,7 @@ func parseAndSendPayload(connection net.Conn, inputData *InputData) {
124
127
}
125
128
126
129
message , err := messaging .CreateMessage_FilePackage (
127
- 2234 ,
130
+ inputData . ID . Bytes () ,
128
131
protobuf .MessageType_PACKAGE ,
129
132
(buffer )[:n ],
130
133
isPayloadFinal )
@@ -153,7 +156,7 @@ func hashFile(path string) (hash []byte) {
153
156
return hasher .Sum (nil )
154
157
}
155
158
156
- func listenForACK (connection net.Conn ) {
159
+ func listenForACK (connection net.Conn , inputData * InputData ) {
157
160
158
161
// TODO: Make into const in message_handler (also server.go)
159
162
// sizePrefix is 4 bytes protobug message size
@@ -172,7 +175,18 @@ func listenForACK(connection net.Conn) {
172
175
if genericProto .GetAck ().ProtoReflect ().IsValid () {
173
176
ackPacket := genericProto .GetAck ()
174
177
175
- log .Info ().Msgf ("ACK packet recieved from server with success flag: %v" , ackPacket .GetServerSuccess ())
178
+ serverResult := ackPacket .GetServerSuccess ()
179
+ ackID , _ := xid .FromBytes (ackPacket .GetId ())
180
+ if ackID != inputData .ID {
181
+ log .Warn ().
182
+ Str ("respone_id" , ackID .String ()).
183
+ Str ("original_id" , inputData .ID .String ()).
184
+ Msg ("Response ID mismatch." )
185
+ }
186
+
187
+ log .Info ().
188
+ Str ("id_back" , ackID .String ()).
189
+ Msgf ("ACK packet recieved from server with success flag: %v" , serverResult )
176
190
}
177
191
}
178
192
@@ -202,6 +216,7 @@ func parseInputArguments() *InputData {
202
216
}
203
217
data := & InputData {
204
218
FileInput : inputPath ,
219
+ ID : xid .New (),
205
220
}
206
221
return data
207
222
}
0 commit comments