aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/volume_udp_client.go
blob: b8bdcec90309bb125975f61e9e6e697ab7664d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package wdclient

import (
	"github.com/chrislusf/seaweedfs/weed/glog"
	"github.com/chrislusf/seaweedfs/weed/pb"
	"io"
	"pack.ag/tftp"
)

// 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
	}

	udpClient, _ := tftp.NewClient(
		tftp.ClientMode(tftp.ModeOctet),
		tftp.ClientBlocksize(9000),
		tftp.ClientWindowsize(16),
		tftp.ClientTimeout(1),
		tftp.ClientTransferSize(true),
		tftp.ClientRetransmit(3),
	)

	fileUrl := "tftp://" + udpAddress + "/" + fileId

	// println("put", fileUrl, "...")
	err = udpClient.Put(fileUrl, fileReader, int64(fileSize))
	if err != nil {
		glog.Errorf("udp put %s: %v", fileUrl, err)
		return
	}
	// println("sent", fileUrl)

	return
}