Skip to content

Commit 3c49641

Browse files
author
lmangani
committed
cleanup
1 parent 39c2af9 commit 3c49641

File tree

2 files changed

+32
-55
lines changed

2 files changed

+32
-55
lines changed

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ services:
4141
- "HEP_SERVER=hep-gigapi"
4242
- "HEP_PORT=9060"
4343
- "HEP_PROTO=udp4"
44-
- "LOOP=1"
45-
restart: no
44+
- "LOOP=400"
45+
- "SLEEP=1800"
46+
restart: unless-stopped
4647
depends_on:
4748
- hep-gigapi

hep-proto.js

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -159,64 +159,40 @@ class HepToLineProtocolConverter {
159159
* @returns {Object} Field key-value pairs
160160
*/
161161
extractFields(header, payload, type) {
162-
const fields = {};
162+
const fields = {
163+
create_date: this.getHepTimestamp(header).getTime(),
164+
time_sec: parseInt(header.timeSeconds, 10),
165+
time_usec: parseInt(header.timeUseconds, 10)
166+
};
163167

164-
// Common fields
165-
fields.create_date = this.getHepTimestamp(header).getTime();
166-
167-
// If the payload is SIP (type 1), try to parse it
168-
if (type === 1 && payload) {
169-
try {
170-
const sipData = getSIP(payload);
171-
if (sipData) {
172-
// Extract SIP headers
173-
if (sipData.headers) {
174-
for (const [key, value] of Object.entries(sipData.headers)) {
175-
// Use the first value if it's an array
176-
let fieldValue = Array.isArray(value) ? value[0] : value;
177-
178-
// Ensure no newlines in the field value
179-
if (typeof fieldValue === 'string') {
180-
fieldValue = fieldValue.replace(/\r\n|\n|\r/g, '\\r\\n');
181-
}
182-
183-
fields[`sip_${key.toLowerCase()}`] = fieldValue;
184-
}
185-
}
186-
187-
// Add method or response code
188-
if (sipData.method) fields.sip_method = sipData.method;
189-
if (sipData.status) fields.sip_status = parseInt(sipData.status, 10);
190-
191-
// Add call-id as a specific field for easier querying
192-
if (sipData.headers && sipData.headers['Call-ID']) {
193-
let callId = Array.isArray(sipData.headers['Call-ID'])
194-
? sipData.headers['Call-ID'][0]
195-
: sipData.headers['Call-ID'];
196-
197-
// Ensure no newlines in call-id
198-
if (typeof callId === 'string') {
199-
callId = callId.replace(/\r\n|\n|\r/g, '\\r\\n');
200-
}
201-
202-
fields.call_id = callId;
203-
}
204-
}
205-
} catch (e) {
206-
if (this.debug) console.error('Error parsing SIP payload:', e);
207-
}
208-
}
209-
210-
// Add the raw payload as a field with escaped newlines
211168
if (payload) {
212169
fields.payload = payload.replace(/\r\n|\n|\r/g, '\\r\\n');
213170
fields.payload_size = payload.length;
214171
}
215-
216-
// Add timestamp components
217-
if (header.timeSeconds) {
218-
fields.time_sec = parseInt(header.timeSeconds, 10);
219-
fields.time_usec = parseInt(header.timeUseconds, 10);
172+
173+
// Fast path for non-SIP packets
174+
if (type !== 1) return fields;
175+
176+
// SIP-specific extraction
177+
try {
178+
const sipData = getSIP(payload);
179+
if (!sipData || !sipData.headers) return fields;
180+
181+
// Extract method/status
182+
if (sipData.method) fields.sip_method = sipData.method;
183+
if (sipData.status) fields.sip_status = parseInt(sipData.status, 10);
184+
185+
// Extract Call-ID directly
186+
const callId = sipData.headers['Call-ID'];
187+
if (callId) fields.call_id = Array.isArray(callId) ? callId[0] : callId;
188+
189+
// Batch process headers
190+
for (const [key, value] of Object.entries(sipData.headers)) {
191+
if (!value) continue;
192+
fields[`sip_${key.toLowerCase()}`] = Array.isArray(value) ? value[0] : value;
193+
}
194+
} catch (e) {
195+
if (this.debug) console.error('Error parsing SIP payload:', e);
220196
}
221197

222198
return fields;

0 commit comments

Comments
 (0)