|
@@ -73,13 +73,13 @@ func (o Oftp) Call() error {
|
|
|
|
|
|
|
|
conn, err = tls.DialWithDialer(netDialer, "tcp", fmt.Sprintf("%s:%d", o.NetworkHost, o.NetworkPort), tlsConfig)
|
|
conn, err = tls.DialWithDialer(netDialer, "tcp", fmt.Sprintf("%s:%d", o.NetworkHost, o.NetworkPort), tlsConfig)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error connecting: %s", err)
|
|
|
}
|
|
}
|
|
|
defer conn.Close()
|
|
defer conn.Close()
|
|
|
} else {
|
|
} else {
|
|
|
conn, err = net.DialTimeout("tcp", fmt.Sprintf("%s:%d", o.NetworkHost, o.NetworkPort), time.Duration(o.NetworkTimeout)*time.Second)
|
|
conn, err = net.DialTimeout("tcp", fmt.Sprintf("%s:%d", o.NetworkHost, o.NetworkPort), time.Duration(o.NetworkTimeout)*time.Second)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error connecting: %s", err)
|
|
|
}
|
|
}
|
|
|
defer conn.Close()
|
|
defer conn.Close()
|
|
|
}
|
|
}
|
|
@@ -91,23 +91,25 @@ func (o Oftp) Call() error {
|
|
|
dataBuf := make([]byte, o.OftpBuffer)
|
|
dataBuf := make([]byte, o.OftpBuffer)
|
|
|
|
|
|
|
|
// Read STH (header)
|
|
// Read STH (header)
|
|
|
|
|
+ conn.SetReadDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
readCnt, err := conn.Read(headerBuf)
|
|
readCnt, err := conn.Read(headerBuf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error reading SSRM stream header: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_, err = parseSTH(headerBuf[:4])
|
|
_, err = parseSTH(headerBuf[:4])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error parsing SSRM stream header: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Read OFTP command
|
|
// Read OFTP command
|
|
|
|
|
+ conn.SetReadDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
readCnt, err = conn.Read(dataBuf)
|
|
readCnt, err = conn.Read(dataBuf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error reading SSRM: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if string(dataBuf[:readCnt]) != "IODETTE FTP READY \r" && string(dataBuf[:readCnt]) != "IODETTE FTP READY \n" {
|
|
if string(dataBuf[:readCnt]) != "IODETTE FTP READY \r" && string(dataBuf[:readCnt]) != "IODETTE FTP READY \n" {
|
|
@@ -118,33 +120,36 @@ func (o Oftp) Call() error {
|
|
|
fmt.Printf("Received SSRM (%d)\n", readCnt)
|
|
fmt.Printf("Received SSRM (%d)\n", readCnt)
|
|
|
|
|
|
|
|
// 3. Send SSID
|
|
// 3. Send SSID
|
|
|
|
|
+ conn.SetWriteDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
writtenCnt, err := conn.Write(o.LocalSSID())
|
|
writtenCnt, err := conn.Write(o.LocalSSID())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error writing SSID: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Sent SSID (%d)\n", writtenCnt)
|
|
fmt.Printf("Sent SSID (%d)\n", writtenCnt)
|
|
|
|
|
|
|
|
// 4. Wait for SSID
|
|
// 4. Wait for SSID
|
|
|
// Read STH (header)
|
|
// Read STH (header)
|
|
|
|
|
+ conn.SetReadDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
readCnt, err = conn.Read(headerBuf)
|
|
readCnt, err = conn.Read(headerBuf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error reading SSID stream header: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_, err = parseSTH(headerBuf[:4])
|
|
_, err = parseSTH(headerBuf[:4])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error parsing SSID: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Read OFTP command
|
|
// Read OFTP command
|
|
|
|
|
+ conn.SetReadDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
readCnt, err = conn.Read(dataBuf)
|
|
readCnt, err = conn.Read(dataBuf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error reading SSID: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 5. Validate SSID
|
|
// 5. Validate SSID
|
|
@@ -165,10 +170,11 @@ func (o Oftp) Call() error {
|
|
|
fmt.Printf("Received SSID (%d)\n", readCnt)
|
|
fmt.Printf("Received SSID (%d)\n", readCnt)
|
|
|
|
|
|
|
|
// 6. Send ESID
|
|
// 6. Send ESID
|
|
|
|
|
+ conn.SetWriteDeadline(time.Now().Add(time.Duration(o.NetworkTimeout)*time.Second))
|
|
|
writtenCnt, err = conn.Write(o.ESID(ESIDCode))
|
|
writtenCnt, err = conn.Write(o.ESID(ESIDCode))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
conn.Close()
|
|
conn.Close()
|
|
|
- return err
|
|
|
|
|
|
|
+ return fmt.Errorf("Error writing ESID: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Sent ESID (%d) with code %d\n", writtenCnt, ESIDCode)
|
|
fmt.Printf("Sent ESID (%d) with code %d\n", writtenCnt, ESIDCode)
|