seaweedfs/weed/wdclient/volume_udp_client.go

47 lines
1 KiB
Go
Raw Normal View History

2021-03-13 18:16:32 +00:00
package wdclient
import (
2021-03-13 18:59:29 +00:00
"github.com/chrislusf/seaweedfs/weed/glog"
2021-03-13 18:16:32 +00:00
"github.com/chrislusf/seaweedfs/weed/pb"
"io"
2021-03-13 20:05:04 +00:00
"pack.ag/tftp"
2021-03-13 18:16:32 +00:00
)
// VolumeTcpClient put/get/delete file chunks directly on volume servers without replication
type VolumeUdpClient struct {
}
func NewVolumeUdpClient() *VolumeUdpClient {
return &VolumeUdpClient{
}
}
func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string, fileSize uint32, fileReader io.Reader) (err error) {
udpAddress, parseErr := pb.ParseServerAddress(volumeServerAddress, 20001)
if parseErr != nil {
return parseErr
}
2021-03-13 20:05:04 +00:00
udpClient, _ := tftp.NewClient(
tftp.ClientMode(tftp.ModeOctet),
tftp.ClientBlocksize(9000),
tftp.ClientWindowsize(16),
tftp.ClientTimeout(1),
tftp.ClientTransferSize(true),
tftp.ClientRetransmit(3),
)
2021-03-13 18:59:29 +00:00
2021-03-13 20:05:04 +00:00
fileUrl := "tftp://" + udpAddress + "/" + fileId
2021-03-13 18:59:29 +00:00
2021-03-13 20:05:04 +00:00
// println("put", fileUrl, "...")
2021-03-13 18:59:29 +00:00
err = udpClient.Put(fileUrl, fileReader, int64(fileSize))
2021-03-13 18:16:32 +00:00
if err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("udp put %s: %v", fileUrl, err)
2021-03-13 18:16:32 +00:00
return
}
2021-03-13 20:05:04 +00:00
// println("sent", fileUrl)
2021-03-13 18:16:32 +00:00
return
}